File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Close BufferedWriter, can't open again?

 
Bret Waldow
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By closing systemOut you are also closing System.out, which means that writing to it will do nothing anymore.
 
Bret Waldow
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic