e.g I have an Object obj,how can I save all its information such as m.getName();m.getFamily() and the others in the file???
+1
A:
since xml is more readable and transferable, i use Simple Framework, or as mentioned you could do simple serialization.
pstanton
2009-11-25 03:44:03
you could also us Xstream.
Milhous
2009-11-25 03:52:17
+5
A:
Using an ObjectOutputStream you can write the object directly into the file.
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("filename.dat")));
out.writeObject(obj);
out.close();
This writes the Object obj out to the file. It can be read back in use an ObjectInputStream().
Vincent Ramdhanie
2009-11-25 03:44:08
This technique can also be used to send arbitrary objects over a socket stream.
Ben S
2009-11-25 03:58:37
A:
If you just need to store the object and retrieve it back as a whole , better go with serialization.
In case, you want a readable file with the contents of the object , use file-IO API to write the contents to a file.
Nrj
2009-11-25 03:45:08
A:
Yet another answer, but Apache Commons Lang has SerializationUtils
SerializationUtils.serialize(Serializable obj, OutputStream outputStream).
John Paulett
2009-11-25 03:49:29