-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBox.java
More file actions
32 lines (26 loc) · 775 Bytes
/
Box.java
File metadata and controls
32 lines (26 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package c14SerializationAndFileIO;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Box implements Serializable{
private int width, height;
public void setWidth(int w) {
width = w;
}
public void setHeight(int h) {
height = h;
}
public static void main(String[] args) {
Box myBox = new Box();
myBox.setHeight(50);
myBox.setWidth(20);
try {
FileOutputStream fs = new FileOutputStream("Box.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(myBox);
os.close();
}catch(Exception ex) {
ex.printStackTrace();
}
}
}