A lot of people around here think that they have to hide their game resources. They don't want other people to change the levels, save-games or textures. What is it, that you care what other people do with your game.

Modding games is fun. Replacing textures with better or more interesting ones or changing the max speed of a taxi in GTA are things people enjoy doing. Why do you want to restrict people having fun with your games?

Just serialize your data in the way which is the most easiest way for you. When you want to be nice save your data as json for example.

Why do you sign your posts with your name? We already know who you are.

Short Off-Topic so everyone knows:I have a couple of mental defects, and writing my name on my stuff that helps me keeping my thoughts sorted.I am doing that with everything, including (but not exluding anything) my clothes.

Thats why I am writing my name on my stuff.

End of Off-Topic.

On-Topic:Another good idea to store data is to use Mojang's NBT data-format (NamedBinaryTags).And the last one: Try making your own format using DataInput/DataOutput-streams, its easy.

I think ObjectOutputStream is the best way to save data. (I never found XML all that readable, to be honest.) But you have to be careful with it.

For starters, when you write out one object, it writes out all the other objects that first object references directly or indirectly--the whole "object graph". Theoretically, one write will save your whole game. But if you're not prepared for it things can get crazy. And if you change an object and write it out again to the same stream, OOS will note that it's already written it and just reference the previous write. So when you read it in, you won't see the changes--the first and second versions will be identical. (This gets really interesting if you're using OOS over a socket.)

Next, use Externalizable rather Serializable. This lets you control exactly what gets written and read. If class A contains class B, whose data is just 3 integers, Externalizable lets you write out the 3 ints rather than the object. When you read A back in, you can recreate B from the 3 ints. Generally, you can avoid writing out data that you don't want to save anyway. (Yeah, you can do this with Serializable via "transient", but with Externalizable you have more control.) And you could encrypt data you didn't want people looking at: passwords or names or pictures or critical numbers.

Be careful when reading data back in. If class A has data that derives from several objects it references, you might want to save space in your file by not saving that data but recreating it from the referenced objects. However, ven when you are done reading in A, the referenced objects may not have their data yet, so you shouldn't try to get values from them. You need to do this by reading in the whole file, then going back and recalculating the derived data. (Or just save it normally in the first place.)

A big benefit to Externalizable is you can include a version number at the start of each class's write. Should you change the class's writeExternal output, increment this number. readExternal can check it and read the correct format every time, even if it changes twice a day. And it can handle big changes too: whole new lists and intricate calculations present no problem at all

Edit: I think I answered some other topic, since this topic is not about the save format. Sorry about that.

The question between the different formats is, how much You want to edit (externally from Your application) the data after You have written it into a file.If it's more like "never" then any binary format will do.However if You need to modify it, then the question is why and who.If it's only You, then any text based format will do.But if it's for modding or for external apps, like map editors, then it would be wiser to pick one of the more standardized formats then roll Your own.This is to avoid making others learn yet another "language".

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

A lot of people around here think that they have to hide their game resources. They don't want other people to change the levels, save-games or textures. What is it, that you care what other people do with your game.

Modding games is fun. Replacing textures with better or more interesting ones or changing the max speed of a taxi in GTA are things people enjoy doing. Why do you want to restrict people having fun with your games?

Just serialize your data in the way which is the most easiest way for you. When you want to be nice save your data as json for example.

This kinda inspired me, I remember having fun changing the maps and modifying properties :p. About the resources, yeah. I'm not going to secure that anymore.

Thanks for all the input from all of you! I made a nice way to save my data, like this:

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org