Skip to content
Advertisement

Recover data after closing a Jar file

I am working with a jar file that deals with a program where I open a window (using JFrame). In this window, I manipulate some data and store some of it in the private fields of a class.

When I close my windows and reopen my jar file, all my data is lost.

How can I save my data so I can access it when I close and open the jar file?

Advertisement

Answer

Your program’s execution is over when you close the window. Consider the .jar file as your executable program handled by JRE. To be able to save your data you may write it to the file system or a database. You can serialize your state and save it to a file then load from the file on reopening.

Java tutorial for Reading, Writing, and Creating Files

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement