java - Reading serialized object from a file? -
I want to write and read a serialable class from an object file. I can write this object in a file, but I can not read the object again and write in the console.
None of these options work. I just want to read the object as it was written on the object file. Trying the code:
Public Zero readBinary1 () throws IOException, ClassNotFoundException {ObjectInputStream input = New ObjectInputStream (New FileInputStream ("G: \\ testobject.tmp")); Input.readObject (); System.out.println (new myClass ()); } Public Zero readBinary1 () throws IOException, ClassNotFoundException {ObjectInputStream input = New ObjectInputStream (New FileInputStream ("G: \\ testobject.tmp")); System.out.println (new myClass (input.readObject ())); }
class:
class myClass indexes serializable {myClass () {} myClass (myClass b) {this.a = b.a; This.b = bb; } Private Static Last Long Serial VERSIONUID = 1 L; Private int A = 0; Private int B = 100; Personal transient int c = 50; }
Code added:
I had to add a toString to my class the way it was suggested to do. It seems that the easiest way to short runs, but I would like to write the object and then be able to read out with the use of toString in the object. Is there a way that I can read and read in the object and then be able to break the information. Dot notation Such as mc.variable1 and mc.variable2 and so on. Before compiling the code I had to type the object to read.
There are some input and output streams that allow the serialization of objects in a file. I am sure there are different ways to wrap the classes to read and also wondering how was the best way to read.
Do this:
myClass read object = (myClass) Input.readObject (); Println (readedObject);
Comments
Post a Comment