For simple program data that needed to be saved I just used properties files before but I was wondering how I can save more complicated application data such as: arraylists e.g..
How would I save such data into a file? And is there a way to save it in a file with my own extension ( so not .properties for example when using the properties method to save data ) and to make sure it cannot be edited by user manually ( which is simply possible with notepad for example for .properties files )?
Thanks in advance.
Best Regards, Skyfe.
The simplest way to do this as stated is to use the built-in Serialization mechanism. Just serialize your ArrayList out to a file using an ObjectOutputStream
wrapped around a FileOutputStream
. As long as each item in your list is serializable, this will work fine.
It's not impossible to modify, but it's fairly obfuscated over, say, a text file (it's binary for starters).