Tag: AMD object SSE string ble tin leo Public input
The java.io.ObjectOutputStream.writeObject (object obj) method writes the specified object to ObjectOutputStream. The class of the object, the signature of the class, and the values of non-transient and non-static fields of the class and all its super-types are written. The default serialized class can be overridden by using the WriteObject and ReadObject methods. Objects referenced by this object are written in the object and the object is fully equivalent to a graph that can be reconstructed by ObjectInputStream.
Statement
The following is a declaration of the Java.io.ObjectOutputStream.writeObject () method
Publicfinalvoid writeobject(Object obj)
Parameters
return value
This method does not return a value.
Abnormal
-
Invalidclassexception-The use of serialization for some of the errors of the class.
-
Notserializableexception--Some objects are serialized and do not implement the Java.io.Serializable interface.
-
IOException--Any exception is thrown by the underlying outputstream.
Example
The following example shows the use of the Java.io.ObjectOutputStream.writeObject () method.
PackageCom.Yiibai;ImportJava.Io.*;Public Class Objectoutputstreamdemo { Public Static voidMain(String[]Args) { StringS= "Hello world!"; IntI= 897648764; Try { Create a new file with an ObjectOutputStream FileOutputStream Out = New FileOutputStream("Test.txt"); ObjectOutputStreamOout= New ObjectOutputStream(Out); Write something in the fileOout.WriteObject(S);Oout.WriteObject(I); Close the streamOout.Close(); Create an ObjectInputStream for the file we created before ObjectInputStreamOis= New ObjectInputStream(New FileInputStream("Test.txt")); Read and print what we wrote before System.Out.println("" + (String)Ois.ReadObject()); System.Out.println("" +Ois.ReadObject()); } Catch (Exception Ex) { Ex. (); } }}
Let's compile and run the above program, which will produce the following results:
Hello World!
897648764
Java.io.ObjectOutputStream.writeObject () Method instance