2

tldr: I'm new to programs with persistent data and am looking for the right way to save/load files. Can anyone point me in the right direction?

I undertaking a project which involves much saving and loading of files between two related systems. Simplified, there is one program which functions as the 'builder' for developers and another which is the 'interface' for clients.

In the 'builder', developers have the functionality to define Items and their possible properties which clients may interact with in the interface. For example, the developer may make an Item called 'car' which may have colour, model, and speed properties; and also an item called 'house' which has dimensions, colour. He can make any number of items, which may be diverse and each will have a few common properties (name, colour) and also an array of different properties.

In the 'interface', clients may choose any number of items into their world. Ie, they may take 2 cars and 1 house, and separately define their properties such that one of the cars is a Fast Red Hotrod, another is a Slow White Van, and the house is Brown and 3x2.

both Car and House are instances of Item, but the client has further specified 2 different instances of Car.

Currently I have saving the different instances (car, house etc) into text files and this seems to be working well, but I'm sure there must be a better way (particularly as I intend the client interface to be runnable on Android). Can anyone point me in the right direction (s) or to some material which would help me make the choice?

3 Answers 3

3

One option is to use Java binary serialization. I would personally avoid that option.

There are plenty of other serialization frameworks around. For example, I've ported Google's Protocol Buffers framework to C#, so I'm generally biased in favour of that - but there are lots of other options too, such as:

These options generally have advantages in terms of:

  • Portability to other platforms (consider if you want to build an iPhone or Windows Phone 7 app in the future)
  • Backward and forward compatibility
  • Human readability (or easy conversion to a human format)
  • Some of them are very compact, too

Admittedly Java binary serialization makes the easy path very easy when it's working - but it can be a pain in other ways. Just my experience.

Sign up to request clarification or add additional context in comments.

2 Comments

nicely summarized. I would like to add CSV formated file and DB to store it.
Serialization must be avoid because it isn't human readable. If for some reasons you have an invalid file, it will be impossible to restore the data using the serialization. It is the same problem in DB if you are using Blob.
1

Databases are excellent places to put persistent data.

Comments

0

You can use Serialization. You'll need to check how you'll access the file/convert on Android.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.