-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileCopy.java
More file actions
44 lines (37 loc) · 1011 Bytes
/
Copy pathFileCopy.java
File metadata and controls
44 lines (37 loc) · 1011 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
33
34
35
36
37
38
39
40
41
42
43
44
package javaIO;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class FileCopy {
public static void main(String[] args) {
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream("/Users/choi/Desktop/aa.jpg");
os = new FileOutputStream("/Users/choi/Desktop/bb.jpg");
int data = -1;
while ((data = is.read()) != -1) {
os.write(data);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("파일을 찾을 수 없습니다." + e);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("파일을 찾을 수 없습니다." + e);
} finally {
try {
if (is != null)
is.close();
if (os != null)
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}