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 I/O and Streams and the fly likes Using ObjectOutputStream....but want to switch 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 » I/O and Streams
Bookmark "Using ObjectOutputStream....but want to switch" Watch "Using ObjectOutputStream....but want to switch" New topic
Author

Using ObjectOutputStream....but want to switch

John Lockheart
Ranch Hand

Joined: Oct 13, 2006
Posts: 115
I'm currently using an ObjectOutputStream to write the contents of my vector to text file. The vector contains objects created from a class hierarchy which implements serializable. Since serializable objects create a binary-format file (which is unreadable), how can I go about using PrintWriter to write out all the objects my vector contains? I'm completely new to all of this, but If i could write a neatly formatted text file, where each object was written on a new line, that would be awesome. Could someone show me how?

Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Here is an example using a PrintWriter to write a Collection:



When run this code will create a file called dogs.txt with the following contents:

[ March 05, 2007: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using ObjectOutputStream....but want to switch
 
Similar Threads
Appending file problem
Still can't write vector to file...?
How to append an object using FileOutputStream
How do I write contents of a vector to file?
Problem in Serialization?