de-Serializing classes
Hi,
I'm using the java Preferences to store some user's prefs. Some of those prefs are stored as Gzipped serialized classes. When I tried to read the xml File generated by the Preferences api and de-serialize thoses classes their names changed.
Exemple I' serialize an instance of "com.package. MyClass" when de-serializing it I get an object on wich getClass().getName() returns "[Lcom.package. MyClass;" (whith the "[L" and the ";" added).
Can you help to fix this problem.
Thank's
[519 byte] By [
taiib] at [2007-9-30 20:52:33]

If your object is an instance of a class then get class is just fully qualified name like:
String string = "";
System.out.println(string.getClass());
It will show output as: class java.lang.String
If it is array then it will show as [Ljava.lang.String; where '[' shows number of dimenssions. If it is two dimenssional array then it will show [[Ljava.lang.String; same for three and n dimenssions.
Try following code.
public static void main(String argv[]) throws Exception{
// make array of strings
String[] strings = { "String1", "String2"};
// make output stream
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("c:\\ser12.txt"));
// write only one string
oos.writeObject(strings[0]);
// write array
oos.writeObject(strings);
// close stream
oos.close();
// make input stream
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("c:\\ser12.txt"));
// read first object
System.out.println(ois.readObject().getClass());
// read second object
System.out.println(ois.readObject().getClass());
// close
ois.close();
}
Regards,