반응형
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package Io;
 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;
 
public class SerializableMain {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
         
        Login obj1 = new Login("gg", new Date());
        Login obj2 = new Login("gg", new Date(114,1,4));
 
        try{
            ObjectOutputStream oos =
                    new ObjectOutputStream(
                            new FileOutputStream("c:\\download\\login.log"));
            oos.writeObject(obj1);
            oos.writeObject(obj2);
            oos.close();
        }catch(Exception e){
            System.out.println(e.getMessage());
        }
 
        try{
            ObjectInputStream ois =
                    new ObjectInputStream(
                            new FileInputStream("c:\\download\\login.log"));
            // 출력하는 메소드에 객체 이름을 넘겨주면
            // toSting()을 호출합니다.
            Login imsi = (Login)ois.readObject();
            System.out.println(imsi);
            imsi = (Login)ois.readObject();
            System.out.println(imsi);
            ois.close();
             
        }catch(Exception e){
            System.out.println(e.getMessage());
        }
         
         
    }
 
}

'JAVA > Java' 카테고리의 다른 글

[JAVA] swing  (0) 2014.11.18
[JAVA] swing ImageButton 만들기  (0) 2014.11.18
[JAVA] File 객체 사용  (0) 2014.11.18
[JAVA] Frame 을 이용한 window 모양 만들기  (0) 2014.11.18
[JAVA] Thread 예제  (0) 2014.11.18

+ Recent posts