I'm assuming I'm mis-understanding how BufferedOutputStream is supposed to work. What I'm trying to do is write to an OutputStream, but not actually write to the underlying file until I flush/close it in a separate operation.
I'm stepping through it, and it appears that the file is created in the first line below, with the new FileOutputStream(fileName).
And later, when I flush and close the OS, it doesn't actually write the data. So what I am left with is an empty file.
You've got two different buffers going here: one in the BufferedWriter, the other in the BufferedOutputStream. The data can get stuck in either buffer until the whole entire stack is flushed: in your example, that would mean flushing the BufferedWriter. Furthermore, there's no guarantee the OS is going to actually put bits onto the disk until you close the disk file, so you might as well just call close() on the BufferedWriter, which will implicitly flush everything along the way.
That said, you've got way too many objects involved here! If you want to write to a file using a BufferedWriter, just say
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
and when you're through, close "writer", and Bob's your uncle.
Thanks for your reply. If I was on my own, I would have done it the way you recommended. However, the reason I'm doing this screwy way is that I'm working from a design given to me, and it was detailed enough to indicate that we're supposed to write to OutputStreams as a kind of buffer, and then flush/close the stream to the file when a different method (commit()) is called.
I'm trying to find out right now if and how much we can deviate from the design.
So, back to the original question. Is it possible to remporarily buffer data in an OutputStream w/out immediately writing to the file?