File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes save an object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "save an object" Watch "save an object" New topic
Author

save an object

Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

how would I save a rectangle and then load it back into my program


Jesus lives
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
Search on the Google for ObjectInputStream, ObjectOutputStream, Serialization. You will get code snippets that will write an object to a file and retrives the same.
Hope that helps!!


-Sam Codean<br />SCJP 1.4 (98%)<br />SCJD 5.0 (87.5%)
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

ok ill look at that thanks
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
A Code Snippet that would help



try
{
FileOutputStream out = new
FileOutputStream(System.getProperty("user.home")
+ File.separator
+ "Library"
+ File.separator
+ "Preferences"
+ File.separator
+ "preferences.dat");

ObjectOutputStream obj_out = new ObjectOutputStream(out);
obj_out.writeObject(this);
}
catch(IOException ioe)
{
JOptionPane.showMessageDialog(null,
Util.props.getPreference("Error.txtPreferencesLost"),
"Error",
JOptionPane.ERROR_MESSAGE);
}
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

ok cheers, ill try that out

thanks for your time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: save an object