开发者

Java Object Array IO

I have an Array of Objects called "person" and i need to save that data, Is there a way to output an array and then input it back into the progr开发者_如何转开发am. I have tried simply outputting the raw String and int data that makes up each "person" and the program never writes that data to the specified txt file. Is there a method or function that can write raw object data and then retrieve it?


You should have a look to ObjectOutputStream and ObjectOutputStream and the Serializable interface. What you are trying to do is to serialize your data to a file and load (deserialize) it back again.


You can use standard Java serialisation. Another trivial solution is to use XStream, which will serialise your objects into/from XML. You don't need to implement specific interfaces or annotate your objects (by default) and you'll get a readable (in XML terms) serialisation, which can be useful.


One approach would be to use Serialization provided by Java. You need to implement the java.io.Serializable interface and write and read to and from the ObjectOutputStream and ObjectInputStream classes to store and retrieve data respectively.


You need serialization. Read this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜