BufferedWriter out = new BufferedWriter( new OutputStreamWriter( new BufferedOutputStream( new FileOutputStream("out.txt") ) ) );
So let me see if I understand this: A byte output stream is opened for file "out.txt". It is then fed to a buffered output stream to make file operations faster. The buffered stream is fed to an output stream writer to bridge from bytes to characters. Finally, this writer is fed to a buffered writer... which adds another layer of buffering?
Hmm...
Yes you are correct.
I think in this case you could do a lot shorter (see also BufferedWriter)
or if you want nice printing functions:
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));
It is possibly that the
FileWriter
creates its own wrapping, but that class will know which way is best.In java Streams and Writers are wrappers so you can assemble them to your own needs (by means of stacking them like you do). The classes don't look at what type of stream/writer they stack on. In your case having several buffers will mean you actually have two buffers, in two different classes. This means they'll take up some extra memory and possibly some performance loss, but most likely you will never notice this (because it is only a little overhead compared to other performance factors).