-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileUtil
More file actions
39 lines (34 loc) · 1.02 KB
/
FileUtil
File metadata and controls
39 lines (34 loc) · 1.02 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
38
39
package com.rooomy.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class FileUtil {
public void copyDirectory(File originDir, String toBaseDir){
File[] listFiles = originDir.listFiles();
for (File file : listFiles) {
File toDir = new File(toBaseDir + File.separator + file.getName());
File newFile = new File(toDir.getAbsolutePath());
copyFile(file, newFile);
}
}
public void copyFile(File originFile, File newFile){
try(FileInputStream fis = new FileInputStream(originFile);
FileOutputStream fos = new FileOutputStream(newFile)){
byte[] by = new byte[2048];
int len;
while((len = fis.read(by)) != -1){
fos.write(by, 0, len);
}
}catch (Exception e) {
System.out.println("文件拷贝失败 : " + originFile.getAbsolutePath());
e.printStackTrace();
}
}
}