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 extensio开发者_开发问答n ( 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.
Serialize to XML, encode/encrypt the data prior to persisting, and then decode/decrypt the data when consuming from your app.
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).
You can use a self contained database like SQLite
精彩评论