This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 58
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: 19654
    
  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: 58
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: 19654
    
  18

I don't think you can.
 
 
subject: Close BufferedWriter, can't open again?
 
Similar Threads
Trying to create an arraylist of objects based on information from a text file
How to refresh a StringBuffer object for creating a HashMap object
wrong output
method construction trouble
JTextArea and saving to a file