Jump to content
  • Advertisement
Sign in to follow this  
ahung89

[java] scanner vs. BufferedReader? printstream vs. FileWriter?

This topic is 3624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all - I have been working through a new textbook for the past week. My previous textbook, which was the one I purchased for my intro to java class, taught the entire I/O chapter using Scanner objects for reading from files and using PrintStream objects for writing to files. My new textbook doesn't even mention scanner and instead talks about using FileWriter, BufferedReader, and FileReader. I personally prefer using scanner just because I am more used to it and feel like it is easier to use. What are the advantages/disadvantages of Scanner and PrintStream objects as opposed to BufferedReader and FileWriter? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Scanner will read/parse tokens from a file; where as using a BufferedReader you would need to do this yourself (Albiet by passing a String to a Scanner!). However using a BufferedReader, you have more control over when and how much data is read from the file as 1 operation.

Obviously the BufferedReader is buffered, so more efficent I/O. I'm not too sure if the same is true for Scanner, it doesn't seem to mention in the Javadoc.

Both are perhaps un-suitable for dealing with objects (apart from Strings) since they only deal with text files.

The FileReader/FileWriter classes are just for convience, they act as wrappers around contructing streams to files; there's no real advantage or dis-advantage to using them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!