I'm using XMLEncoders and XMLDecoders for storage of
java objects. Currently I've tried on simple data types only. But the problem is if I want to operate on the XMLEncoder created file from two different programs, then it is giving errors. In one program I'm executing
XMLEncoder e = new XMLEncoder(new BufferedOutputStream
(new FileOutputStream("polledobjects.xml")));
e.writeObject(...);
e.writeObject(...);
e.close();
and in another program I want to append to append a few more objects in the same polledobjects.xml, so I created another XML encoder object and opened the polledobjects.xml in append mode.
XMLEncoder e1 = new XMLEncoder(new BufferedOutputStream(new
FileOutputStream("polledobjects.xml",true)));
e1.writeObject(...);
e1.writeObject(...);
e1.close();
Now, Decoder works fine till the point it goes thru xml portion created by the first program, but as soon as it reached xml portion created by the second program, it gives the error->
java.lang.ArrayIndexOutOfBoundsException: 2
at java.beans.ObjectHandler.dequeueResult(XMLDecoder.java:272)
at java.beans.XMLDecoder.readObject(XMLDecoder.java:150)
at Convert.main(Convert.java:57)
XML file created is :-
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2" class="java.beans.XMLDecoder">
<object class="Data_to_Poll">
<void property="active">
<boolean>true</boolean>
</void>
<void property="agent">
<
string>192.9.200.151</string>
</void>
</object>
</java>
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2" class="java.beans.XMLDecoder">
<object class="Data_to_Poll">
<void property="active">
<boolean>true</boolean>
</void>
<void property="agent">
<string>192.9.200.151</string>
</void>
</object>
</java>
I know it is giving problems b'cos it is encountering <?xml tag 2 times in the same xml document, but what should I do if I want to append in the same xml file and in the second program nothing more than filename is known...
plz. help me out....