java/코드 리뷰

16. bytestream - (1) FileCopyDemo1 ( 파일 복사 )

Astaroth아스 2020. 4. 27. 16:04
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
package bytestream;
 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
 
public class FileCopyDemo1 {
    
    public static void main(String[] args) throws FileNotFoundException, IOException {
        
        // sample2.txt를 읽어오는 스트림
        FileInputStream fis = new FileInputStream("c:/files/sample2.txt");
        // sample3.txt 파일에 기록하는 스트림
        FileOutputStream fos = new FileOutputStream("c:/files/sample3.txt");
 
        int value1 = fis.read();
        fos.write(value1);
 
        int value2 = fis.read();
        fos.write(value2);
 
        int value3 = fis.read();
        fos.write(value3);
 
        int value4 = fis.read();
        fos.write(value4);
 
        int value5 = fis.read();
        fos.write(value5);
        
        fis.close();
        fos.close();
        
    }
}