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 & HelpSyntax Questions › Safest way to continuously save text to a file
Page Index Toggle Pages: 1
Safest way to continuously save text to a file (Read 661 times)
Safest way to continuously save text to a file
Mar 12th, 2010, 7:47am
 
Currently I have the user interacting with the sketch which gives me the following string:

timeStamp + "\t" + userID + "\t" + num

where timestamp is the time they interacted, userID is a unique id they entered, and num is the number of times they have used the program.

I want to save this information to a file and have it permanently there.  But the createWrite method requires output to be flushed and closed on exit in order for the file to be readable.  Meaning if the program crashes before doing this, i'll loose all this information.

Is there a better way to do this?

Also - in order for 'num' to work, each time a user interacts, i need to read and parse all the previous lines, seeing if the userIDs match, and if they do, don't enter a new line, but increase that users num by 1.

Writing this I get the feeling what I need is an arrayList.  But i am still not sure on writing this to a file.

Thanks,
TB
Re: Safest way to continuously save text to a file
Reply #1 - Mar 12th, 2010, 7:53am
 
you can flush it just after it is written to the file. so in this case it is not lost if the programm crashes
Re: Safest way to continuously save text to a file
Reply #2 - Mar 13th, 2010, 4:44am
 
i thought of another option that might work for you.

if you intend to maintain all information created within a sketch even after closing it you can easily use xml to achieve so; all you have to do is save the information to the xml file retrieving it when needed. if i recall correctly flushing would not be required for the file to be readable.

i guess this way you can prevent losing information even if the sketch crashes.

check http://processing.org/reference/XMLElement.html and its methods.

hope this helps.
p
Page Index Toggle Pages: 1