This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
 
Similar Threads
WA #1.....word association
Garbage Collector
How to provide these functionalities
applet help please
Grails: save() works, update and delete() do not work