posted 18 years ago
[CR]: but I couldn't find one with a FileReader as a parameter.
public Scanner(Readable source)
All Readers now retroactively implement Readable, so this constructor will accept a FileReader. If you've already got a FileReader for some reason, you might as well use this constructor I suppose. But in general I see no benefit to creating a FileReader just to pass it to a Scanner; I would rather just use one of the consrtuctors that takes a File. Also note that with a FileReader there's no way to specify a particular encoding. Until now you needed to construct an InputStreamReader wrapped around a FileInputStream, if you wanted a particular encoding. Now Scanner allows you to directly specify encoding along with a File - much simpler.
Many programmers will overlook the possibility that they need to specify an encoding other than the default, but at least Scanner makes it easy to do, if and when the need is discovered. FileReader was originally a convenience class for reading text from files; with Scanner we have a more powerful convenience class for the same thing. I would pretty much forget about FileReader in code for 1.5+. Scanners are the way to go.
[ July 19, 2006: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister