File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Close BufferedWriter, can't open again? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Close BufferedWriter, can Watch "Close BufferedWriter, can New topic
Author

Close BufferedWriter, can't open again?

Bret Waldow
Ranch Hand

Joined: Aug 04, 2000
Posts: 59
Hi,
I ran across this in a small demo I wrote, and pared it down. The behaviour is a console app, give it several text files on input line and it prints the contents out. If I uncomment the "systemOut.close();" line, it only prints the first one. I can't figure out why - can anyone tell me?

Thanks in advance.

Sample output with line commented out:

With the line uncommented, only the lines from Input1 appear?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

By closing systemOut you are also closing System.out, which means that writing to it will do nothing anymore.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bret Waldow
Ranch Hand

Joined: Aug 04, 2000
Posts: 59
I thought of that possibility a few minutes ago, and then thought, "no, that's ridiculous. Why would they allow that?"

But it does fit with the symptoms. An interesting design choice.

Do you know of a way to then re-open System.out? "new System.out()"?

And yes, I can understand the idea of "don't do that".

Thanks,
Bret
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

I don't think you can.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Close BufferedWriter, can't open again?