import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class FuZhiDuoCengWenJian {
public static void main(String[] args) throws IOException {
String s = "F:\\学习资料\\练习题";
String s1 = "E:\\复制文件";
File f = new File(s);
File f1 = new File(s1);
menth(f, f1);
}
public static void menth(File a, File b) throws IOException {
File[] files = a.listFiles();
for (File file : files) {
if (file.isFile()) {
FileInputStream fi = new FileInputStream(file);
String s = file.getName();
File f = new File(b, s);
FileOutputStream fo = new FileOutputStream(f);
byte[] arr = new byte[1024];
int a1;
while ((a1 = fi.read(arr)) != -1) {
fo.write(arr, 0, a1);
}
fo.close();
fi.close();
} else if (file.isDirectory()) {
String s = file.getName();
File f = new File(b, s);
f.mkdirs();
menth(file, f);
}
}
}
}有点烧脑 |
|