| | |
Scanner or BufferedReader ?
| View Poll Results: Scanner or BufferedReader? | |||
| Scanner | | 3 | 33.33% |
| BufferedReader | | 6 | 66.67% |
| Voters: 9. You may not vote on this poll | |||
Thread Solved |
This is not much of a question, but a discussion and searching for opinions. I have seen that many use the Scanner class for getting input from the keyboard. Some, like myself, use the BufferedReader.
Why will someone use one over the other?
Or they both do the same thing when it comes something simple as that and their real difference is when it comes to using them for something more complex?
Why will someone use one over the other?
Or they both do the same thing when it comes something simple as that and their real difference is when it comes to using them for something more complex?
Check out my New Bike at my Public Profile at the "About Me" tab
Well im voting for the scanner. Thats how i learnt and thats how i go, i dont find anything wrong with it so i stay that way.. addmitedly i really dont know a thing about Buffered Reader anyway, so it could be loads better for all i know.
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
•
•
Join Date: Jan 2009
Posts: 34
Reputation:
Solved Threads: 3
Ditto... If i ever begin to study BufferedReader I'll discuss it further. What are the differences anyway? Any one that is advanced plz reply?
Ehmmm where do I find this in Java Microedition? 
Neither me. For now I work in JME, Swing or Web Development so no.

Neither me. For now I work in JME, Swing or Web Development so no.
Last edited by peter_budo; Jan 22nd, 2009 at 3:57 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
I used to use the buffered reader in September but I started to find when in my contests that the Scanner is better.
Since I can read individual elements at a time, I don't have to worry about splitting and parsing into integers.
Say my input file is:
With the buffered reader, I would have to read things in line at a time, split it up and parse it into integers. Thus the buffered reader seems to make input a lot tougher.
Buffered reader:
With the scanner I don't have to read in each line as a string and parse it with the Integer class.
Scanner:
Also I can have Scanner that parses each individual element in a String. So the Scanner class is quite helpful - and in my opinion a lot better than the buffered reader.
Prints:
So that is why I believe the Scanner class is better than the Buffered Reader.
Since I can read individual elements at a time, I don't have to worry about splitting and parsing into integers.
Say my input file is:
•
•
•
•
4 4
*...
....
.*..
Buffered reader:
Java Syntax (Toggle Plain Text)
BufferedReader br = new BufferedReader(new FileReader("DATA1.txt")); String[] arsNums = br.readLine().split(" "); int nX = Integer.parseInt(arsNums[0]); int nY = Integer.parseInt(arsNums[1]);
With the scanner I don't have to read in each line as a string and parse it with the Integer class.
Scanner:
Java Syntax (Toggle Plain Text)
Scanner sin = new Scanner(new FileReader("DATA1.txt")); int nX = sin.nextInt(); int nY = sin.nextInt(); char[][] arcGrid = new char[nX][nY]; String sLine = ""; for (int x=0;x<nX;x++) { sLine = sin.next(); for (int y=0;y<nY;y++) { arcGrid[x][y] = sLine.charAt(y); } }
Also I can have Scanner that parses each individual element in a String. So the Scanner class is quite helpful - and in my opinion a lot better than the buffered reader.
Java Syntax (Toggle Plain Text)
String sText = "Four men went down to the store, to catch frogs!"; Scanner sin = new Scanner(sText); while (sin.hasNext()) { System.out.println(sin.next()); }
Prints:
•
•
•
•
Four
men
went
down
to the
store,
to
catch
frogs!
I don't write console applications either but when I first begun I knew from my book only the BufferedReader. So since we've seen many students here asking how to read files and input from the console I thought to get other opinions and discuss the topic.
There has to be some reason why someone would choose to use one over the other
There has to be some reason why someone would choose to use one over the other
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
•
•
I don't write console applications either but when I first begun I knew from my book only the BufferedReader.
That was most probably because when we learnt Java, java.util.Scanner did not exist.
I started learning Java from the 1.4.2 version of the JDK, and Scanner was introduced only in the 1.5 version and since console input is not so widely used by many of us, we opted to stick with good ol' BufferedReader.
Last edited by stephen84s; Jan 23rd, 2009 at 7:13 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
•
•
•
•
That was most probably because when we learnt Java, java.util.Scanner did not exist.
I started learning Java from the 1.4.2 version of the JDK, and Scanner was introduced only in the 1.5 version and since console input is not so widely used by many of us, we opted to stick with good ol' BufferedReader.
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- Simple Scanner Class Question (Java)
- Can't find Scanner class? (Java)
- no luck with reading integers from file in arraylist (Java)
- Binary Search Tree (Java)
- scanner class and switch statments (Java)
- Help with Idea?!? (Java)
- Read a specific line from a text file - how to ? (Java)
- Need help with project using jGRASP (Java)
- Question about the Scanner class (Java)
Other Threads in the Java Forum
- Previous Thread: need help here... subject scheduler using topological sorting
- Next Thread: Scanner string and integer mix..
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing system test textfields threads time title tree tutorial-sample ubuntu update windows working






