Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing into files

 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to build a program to write to a file, i initialized the filename in a static piece of code so that if multiple threads are even writing into the file, the file is initialized only once. I don't want to close the file until the whole writing is finsihed, how and when can i close the file.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Sonia wrote:I don't want to close the file until the whole writing is finsihed, how and when can i close the file.


How: by calling close() on the stream.

When: As you stated, when the "whole writing is finished." I'm guessing your next question is going to be, "How do I know when it's done?" We can't answer that. Only you can.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your writeToFile method, you may wish to closely examine which object you are synchronising.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50266
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would also probably be better off buffering your output stream.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic