I have only used Java Channels and BufferedOutputStream and the input counter part for reading and writing simple integers and some strings here and there to the file.
However I do not understand the use of all these classes when there is java.util.Scanner class that provides easy ways to read and write to the files.
Java veterans please tell me the use of Channels and Streams over Scanner.
- 2Have you taken a look at docs.oracle.com/javase/tutorial/essential/io/index.html ?Martijn Verburg– Martijn Verburg2012-09-11 14:23:07 +00:00Commented Sep 11, 2012 at 14:23
- 3For one thing, java.util.Scanner can not be used to write to files.Michael Borgwardt– Michael Borgwardt2012-09-11 14:25:39 +00:00Commented Sep 11, 2012 at 14:25
- @MartijnVerburg: Nope, I was using Ivor Horton's book.Dummy Derp– Dummy Derp2012-09-11 14:27:23 +00:00Commented Sep 11, 2012 at 14:27
Add a comment |
1 Answer
You use Java Channels for applications that have much more traffic coming to them, not just for simple stuff. Same goes, (kind of) for buffered IO. If you're writing to a file, and you're using any considerable amount of output, then you're going to want to use a buffered IO driver. If you're reading from a file, and don't have to read that much information, use Scanner, otherwise, use buffered IO.