Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
You’ve made the perfect pattern. You want to save the pattern. You could grab a piece of paper and start scribbling it down, but instead you hit the Save button (or choose Save from the File menu). Then you give it a name, pick a directory, and exhale knowing that your masterpiece won’t go out the window with the blue screen of death.
You have lots of options for how to save the state of your Java program, and what you choose will probably depend on how you plan to use the saved state. Here are the options we’ll be looking at in this chapter.
If your data will be used by only the Java program that generated it:
Use serialization
Write a file that holds flattened (serialized) objects. Then have your program read the serialized objects from the file and inflate them back into living, breathing, heap-inhabiting objects.