Question

I am running very time-consuming analyses and only their (very short) results are outputed to text file using printWriter.

Since my computer broke down twice recently and the results were not saved since the process wasn't finished (it only saves the file whenever printerWriter.close() is reached at the end), I was wondering whether there was a way to save the file various times throughout the process and update the output file each time. In that case, if the computer crashes at least parts of the results would still be available and wouldn't have to be repeated.

Some details:

A process is repeated for n=10 iterations using different (fixed) random seeds. After each iteration, I would like to save the results obtained in the iterations run so far. Thus, the chosen output file would have to be updated and saved after each iteration.

Was it helpful?

Solution

I suspect all you're looking for is calling flush on the PrintWriter.

Sounds like you should potentially look for a new computer, mind you...

OTHER TIPS

You can create PrintWriter using:

    PrintWriter writer = new PrintWriter(new FileWriter("file name"), true);

to get output buffer flushed automatically when println() or format() or printf() called on writer. Or you can manually use writer.flush() to flush output buffer when you desire.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top