0

Its a general question I am trying to deal with.

I used to program in java and just to implement the serializable.io interface in my sysData class inside my model package and then in the view Package I would just look for a single file ".ser" and either load or save into it.

But now, I want some of my classes to be saved into one ".ser" file and the others to another separate ".ser" file and I can't seem to find a way to figure that out.

I would be grateful if someone can hint me out on the concept of how to save some objects into one ".ser" file and the other bulk of objects to a different ".ser" file.

Thank you,

Tom

Tom
  • 343
  • 3
  • 12
  • have a look may be it will give yo an idea http://stackoverflow.com/questions/3470138/writing-many-java-objects-to-a-single-file – Zia Nov 24 '16 at 06:02
  • Unless Java serialization is required, another serialization format may be worth looking into. The process will be similar in both cases: open a different serializer using a different output stream and write the given object graph to the appropriate serializer. Trying to process the serialized stream itself will .. not be fun. – user2864740 Nov 24 '16 at 06:04
  • We have good experience using [XStream](http://x-stream.github.io/) instead of vanilla serialization. – cheffe Nov 24 '16 at 06:23

1 Answers1

0

The java.io.Serializable interface allows you to save your data object to a data stream. This stream could be a file or any other persistent storage form or even send it over the network.

Have each of the classes you want to store implement the Serializable interface. Then use some sort of a mapping that knows which Class/object needs to be saved to which file.

For example,

A.class = A.ser
B.class = B.ser
C.class = C.ser
... and so on ...

Use this to save it and load data between the JVM and the file system.

Hope this helps!

anacron
  • 6,443
  • 2
  • 26
  • 31