How to save data in a program

  • You can either use saveStrings() again and write over the existing file (when you load it, add data and save it with the same name, it’s like append data to the existing file, like for a high score)

  • But you can also generate a new text file. For example just incrementing a number (so file name is myfile1.txt, myfile2.txt…). Or using a file name that is built from date and current time (when you save only once per second maximum).

  • There is also a full Save as… dialogue in processing. Here you can enter a file name (like when you save a Sketch in processing).

See reference for all commands.


date time stamp for file name

  // make date time stamp (the expression nf(n,2) means leading zero: 2 becomes 02)
  String dateTimeStamp = year() 
    + nf(month(), 2) 
    + nf(day(), 2) 
    + "-" 
    + nf(hour(), 2)
    + nf(minute(), 2)
    + nf(second(), 2)
    +".txt";

Save as… dialogue

see selectOutput() in reference : Reference / Processing.org

it’s selectOutput() / Reference / Processing.org

1 Like