import java.io.*;
class ABC implements Serializable { }
public class SerializeABC {
public static void main(String[] args) {
ABC ab = new ABC();
try {
FileOutputStream fs = newFileOutputStream(”testSer.ser”);
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(ab);
os.close();
} catch (Exception e) { e.printStackTrace(); }
try {
FileInputStream fis = new FileInputStream(”testSer.ser”);
ObjectInputStream ois = new ObjectInputStream(fis);
ab = (ABC) ois.readObject();
ois.close();
} catch (Exception e) { e.printStackTrace(); }
}
}
What will be the output of the following code?
Author: Daisy WilliamsOct 5
What are the methods of ObjectOutputStream?
Author: Daisy WilliamsOct 3
The following table depicts the commonly used methods defined by ObjectOutputStream:
| Method Name | Description |
|---|---|
| void close() | Closes the invoking stream with an IOException. |
| void flush() | Flushes the output buffers. |
| void write(int b) | Writes a single byte to the invoking stream. |
| void writeChar(int c) | Writes a char to the invoking stream. |
| void write(byte buffer[]) | Writes an array of byte to the invoking stream. |
| final void writeObject(Object o) | Writes an object to the invoking stream. |
| void writeBoolean(boolean b) | Writes a boolean to the invoking stream. |
| void write(byte buffer[], int offset, int numBytes) | Writes a subrange of numBytes bytes from the array buffer. |