We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Save out a PrintWriter file upon exit
Page Index Toggle Pages: 1
Save out a PrintWriter file upon exit (Read 613 times)
Save out a PrintWriter file upon exit
Feb 11th, 2010, 4:34pm
 
I've got a PrintWriter object that I want to save (flush) and close out whenever the sketch is quit.  Currently, I'm trying to catch that this way:

public void stop() {
 output.flush();  //Write the remaining data
 output.close();  //Finish the file
 super.stop();
}

I was hoping this would run the needed .flush() and .close() no matter how sketch was quit.

But it's not working — my printwriter files turn up empty.  Any thoughts?
Re: Save out a PrintWriter file upon exit
Reply #1 - Feb 11th, 2010, 7:01pm
 
Never mind — I got it!

Instead of calling .flush() in stop(), I call it after every time that I output more data to the file, as in:

   output.println("one line of data goes here");
   output.flush();  //Write the data to file

Then I call .close() in stop().  Not sure if that's a proper approach, but it's working.
Page Index Toggle Pages: 1