 |
|

What is printed by this program?
import java.io.*;
class Info implements Serializable {
private String s;
private char c;
private int n;
Info(String ss, char cc, int nn) {
s = ss; c = cc; n = nn;
}
public String toString() {
return s + " | " + c + " | " + n;
}
}
public class IO {
final String FILE = "data.txt";
IO() {
write();
read();
}
void write() {
Info info1= new Info("Abc", 'x', 1);
Info info2= new Info("Def", 'y', 2);
Info info3= new Info("Ghi", 'z', 3);
try {
ObjectOutputStream os =
new ObjectOutputStream(
new FileOutputStream(FILE));
os.writeObject(info3);
os.writeObject(info1);
os.writeObject(info2);
} catch (IOException e) {
System.err.println(
"Output Error: " + FILE);
}
}
void read() {
Info info;
try {
ObjectInputStream is =
new ObjectInputStream(
new FileInputStream(FILE));
while (true) {
info =
(Info) is.readObject();
System.out.println(info);
}
} catch (EOFException e) {
} catch (IOException e) {
System.err.println(
"Input error: " + FILE);
} catch (ClassNotFoundException e) {
System.err.println(
"Class error: " + FILE);
}
}
public static void main(String[] args) {
new IO();
}
}
|

 |
| |
|
|
 |