File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing into files

 
Jacob Sonia
Ranch Hand
Posts: 179
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would also probably be better off buffering your output stream.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic