N
Novice
I'm try to wrap my head around the basic I/O classes, especially how to
choose the one I need for a given job.
I understand that Streams are for bytes and Readers and Writers are for
characters and I think I understand the distinction between bytes and
characters.
Let's say that I want to write characters, as opposed to bytes. How do I
decide which subclass of Writer I want to use? I'm not clear on when
BufferedWriter, say, is preferable to PrintWriter.
I also get very confused when I see Streams, Readers and Writers wrapped
within one another. For example, this snippet confuses me:
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream
("outfilename"), "UTF8"));
Why wrap FileOutputStream within OutputStreamWriter within BufferedWriter?
Why not just BufferedWriter, say, to do everything? What is actually
happening at execution time when you execute this code?
Also, when do I use this basic I/O and when is it better to use the NIO
classes?
I've looked at a few different tutorials but the penny hasn't dropped for
me yet. Any advice on how to answer these questions for myself?
choose the one I need for a given job.
I understand that Streams are for bytes and Readers and Writers are for
characters and I think I understand the distinction between bytes and
characters.
Let's say that I want to write characters, as opposed to bytes. How do I
decide which subclass of Writer I want to use? I'm not clear on when
BufferedWriter, say, is preferable to PrintWriter.
I also get very confused when I see Streams, Readers and Writers wrapped
within one another. For example, this snippet confuses me:
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream
("outfilename"), "UTF8"));
Why wrap FileOutputStream within OutputStreamWriter within BufferedWriter?
Why not just BufferedWriter, say, to do everything? What is actually
happening at execution time when you execute this code?
Also, when do I use this basic I/O and when is it better to use the NIO
classes?
I've looked at a few different tutorials but the penny hasn't dropped for
me yet. Any advice on how to answer these questions for myself?