But I don't understand why this doesn't produce errors. What I currently understand is that a character stream sent to System.out has to pass through each method before making its way onto output.txt

I also read this technique is called wrapping?

I don't, however, understand why "new BufferedWriter()" and "new FileWriter()" work by themselves inside those parameters. They both look like half a declaration to me. Does the "out" variable get assigned to one complicated object, or does it, in effect, create several?

But I don't understand why this doesn't produce errors. What I currently understand is that a character stream sent to System.out has to pass through each method before making its way onto output.txt

I also read this technique is called wrapping?

I don't, however, understand why "new BufferedWriter()" and "new FileWriter()" work by themselves inside those parameters. They both look like half a declaration to me. Does the "out" variable get assigned to one complicated object, or does it, in effect, create several?

... and forget about variables fw and bw. Those 'wrappers' (or 'decorators') each add some functionality to the object it wraps. I wrote a blog entry in this forum once that discusses those wrappers. (see the top of this page for the blog section).

Re: Nested constructors: why do they work?

I found it, but I'll have to bookmark the article for later, a few lines of your code are beyond me. Not for long, though. :p

Speaking of which, while searching for your blog I found this one, which is related; I'd been trying to figure out buffering.

I gleaned that character streams will request disc access often, whereas a buffered stream will only send chunks of data, mitigating the number of disc access requests, and therefore overhead. Does that sound right?

Re: Nested constructors: why do they work?

I found it, but I'll have to bookmark the article for later, a few lines of your code are beyond me. Not for long, though. :p

You can always post a comment there if you want; if some of my code is unclear, I'd be happy to receive comments on it and I happily change the code where needed ...

Originally Posted by Daimoth

Speaking of which, while searching for your blog I found this one, which is related; I'd been trying to figure out buffering.

I gleaned that character streams will request disc access often, whereas a buffered stream will only send chunks of data, mitigating the number of disc access requests, and therefore overhead. Does that sound right?

Yup, right; when you hit the OS, you end up in a queue (waiting to be serviced) and when the OS has to hit the hard disk, things become even slower. Better read a lot of bytes from the hard disk in one go and don't go through all that hoopla for every single byte.