Skip to main content
gamedev.net
🔒 Locked

[java] saving object files

Started by role 0 replies 250+ views
Original Post
role
role
is it possible to save group of class object? like this: i have a class that hold : object position : int x,y object image number : int pic object hp : int hp object float : boolean floAt object visible : boolean visiBle and something that refer to another object : MainObject mainObject and then another class : map size : Dimension dimension link to another map : String warp i want to save a group of these two classes object, and later i can erase the one that i don''t use. plz show me a link for saving & loading file or a code maybe to save these classes i have lack knowledge for IO file thank you
BlackArrow
BlackArrow
If you''re simply looking to save a class file to the hard drive, take a look at serialization:

http://java.sun.com/docs/books/tutorial/essential/io/serialization.html

Serialization allows you to write data from a class file such that you can later reconstruct the object. Here''s an example of how to save an object:

  
MyClass mclass = new MyClass();

FileOutputStream out = new FileOutputStream("datafile");
ObjectOutputStream str = new ObjectOutputStream(out);
str.writeObject(mclass);
str.flush();

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.