Originally posted by luc comeau:
Maybe she just wants the class to get used to the idea of using streams, since they are used for alot of things in java. I think maybe by beginner she just meant that its concealing the "tuff" part of doing I/O. Just my opinion
Thats a possibility, but that doesn't explain her assertion (in my mind) that the BufferedReader offers "more control" over the input stream. But since she is just beginning to cover exception handling, this is a definite possibility.
Originally posted by Keith Lynn:
\BufferedReader doesn't rely on breaking up its input into tokens. It allows you to read character by character if you want. ...You can also read chunks of character arrays using the BufferedReader. So I would say, just as a personal opinion, that you do have more flexibility with BufferedReader.
I can live with that. Scanner has no facility for reading character by character except reading an entire line and breaking it up into a character array.
You can easily read a whole line with Scanner too, using nextLine(). It's also possible to read one character at a time with next() if you useDelimiter(""), but this is not obvious. Of course you can also read a line or other String and then use charAt() to look it individual chars if that's what you want.
The one thing I don't quite like about Scanner is that if an IOException occurs in an underlying stream, it can be easily overlooked. Admittedly the most common IOExceptions are probably FileNotFound, which is thrown as expected by the new Scanner(File) constructor if there's a problem finding a file. But if other problems occur after the Scanner is created - you lose a network connection, for example - then it looks like the various hasNextXXX() methods will simply return false. You really should check the value of scanner.ioException() when you're done, so see if everything's really OK:
This isn't any more work than catching exceptions from stream - the danger though is that Scanner makes it all too easy to simply forget to do it. Something to beware of...