aspose file tools*
The moose likes Beginning Java and the fly likes writing into files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "writing into files" Watch "writing into files" New topic
Author

writing into files

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Nov 09, 2011
Posts: 1012
    
    5

In your writeToFile method, you may wish to closely examine which object you are synchronising.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
You would also probably be better off buffering your output stream.
 
Don't get me started about those stupid light bulbs.
 
subject: writing into files