Results 1 to 1 of 1
- 12-22-2008, 06:16 PM #1
InputStream, Iterator, readObject issues while deserializing multiple objects
I'm trying to add all objects within a file to an ArrayList using an ObjectInputStream and Iterator. This is being used to deserialize all objects in a file at once into an arraylist and then add the contents of an arraylist to a tree. No matter what I try I keep getting TypeCast exceptions, StreamCorrupt exceptions, and endless while loops.
I'm having no issues actually deserializing anything and adding it to the tree. Just trying to repeat the process if the branch contains > 1 element.
writeObject is invoked upon instantiation of any object. The object calls the save_object method
from here I call the load_object method that tries to deserialize each object and add it to the arraylist.Java Code://this method works properly. I have checked the text files and all objects //are being written private static void save_object(Server object, File fileName) throws IOException { ObjectOutputStream objstream = new ObjectOutputStream(new FileOutputStream(fileName,true)); System.out.println("Writing "+object.getName()+ " to file: "+fileName); objstream.writeObject(object); objstream.close(); }
I know logically what I'm supposed to be doing to get this working but nothing I try works. Can someone tell me what needs to be done to get this working?Java Code:public static ArrayList<Server> load_object() throws Exception { ObjectInputStream objstream = new ObjectInputStream(new FileInputStream(NavigationView.serverFile)); ArrayList<Server> servers = new ArrayList<Server>(); Server server = null; //java.io.StreamCorruptedException: invalid type code: AC // at java.io.ObjectInputStream.readObject0(Unknown Source) // at java.io.ObjectInputStream.readObject(Unknown Source) // at groups.Server.load_object(Server.java:46) // this occurs at the line after my loop while(objstream.readObject() != null){ server = (Server)objstream.readObject(); System.out.println("Adding "+server.getName()); servers.add(server); } objstream.close(); return servers; }Liberty has never come from the government.
Liberty has always come from the subjects of government.
The history of liberty is the history of resistance.
The history of liberty is a history of the limitation of governmental power, not the increase of it.
Similar Threads
-
how to deserialize multiple objects in a file
By xcallmejudasx in forum Advanced JavaReplies: 11Last Post: 12-16-2008, 05:29 PM -
iterator issues
By orchid in forum New To JavaReplies: 2Last Post: 08-12-2008, 01:43 PM -
Can i use the same statement and resultset objects for executing multiple query?
By RadhaJayalakshmi in forum JDBCReplies: 2Last Post: 07-18-2008, 01:13 PM -
Can I store multiple objects in an array
By lareauk in forum New To JavaReplies: 9Last Post: 05-29-2008, 03:57 AM -
Can I use vectors to store multiple types of objects
By Nathand in forum Advanced JavaReplies: 6Last Post: 04-28-2008, 07:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks