Putting multiple objects in a file
I need to put several colors and a few dozen ints into a file. How would I save them into that file? I know how to put things in a file, but how would I separate the objects, and how would I be able to access each one individually once the program is being used? Thank you for any help.
Re: Putting multiple objects in a file
You could write the values of the objects to file in a pre-dermined file format of your choice, or you could serialize the objects into the file:
Discover the secrets of the Java Serialization API
Re: Putting multiple objects in a file
I'm really confused now. That didn't make much sense to me.
Re: Putting multiple objects in a file
The article looks pretty detailed to me. What *specifically* are you confused about?
Re: Putting multiple objects in a file
Well. What exactly is serialization? How do I read the data after it is written? How do I choose what portion to read?
Re: Putting multiple objects in a file
Serialization is one way that Java allows you to write objects to and read objects from a file (or other binary form). It's a bit much to explain in a forum, and you're much better off reading up about it from a tutorial (at least to start with) and then asking your specific questions about what you don't understand in the tutorial here. If the above tutorial doesn't work well for you, please check out others, such as this one, since much has been written on this subject.