forked from Drun1baby/JavaSecurityLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileCopy.java
More file actions
37 lines (34 loc) · 1.16 KB
/
Copy pathFileCopy.java
File metadata and controls
37 lines (34 loc) · 1.16 KB
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 src.IOStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
// 文件拷贝操作
public class FileCopy {
public static void main(String[] args) {
copyFile();
}
public static void copyFile(){
String srcFilename = "Serialable/src/IOStream/CreateForFile/new1.txt";
String desFilename = "Serialable/src/IOStream/CreateForFile/new2.txt";
FileInputStream fileInputStream = null;
FileOutputStream fileOutputStream = null;
try {
fileInputStream = new FileInputStream(srcFilename);
fileOutputStream = new FileOutputStream(desFilename);
byte[] cache = new byte[1024];
int readLen = 0;
while((readLen = fileInputStream.read(cache)) != -1){
fileOutputStream.write(cache, 0, readLen);
}
} catch (IOException e){
e.printStackTrace();
} finally {
try {
fileInputStream.close();
fileOutputStream.close();
} catch (IOException e){
e.printStackTrace();
}
}
}
}