package com.heima.Day23;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Test10 {
/**
*
*/
public static void main(String[] args) throws Exception {
File f = new File("F:\\MyWife");
File fe = new File("F:\\copy");
copy(f,fe);
}
public static void copy(File f, File fe) {
File fil = new File(fe, f.getName());
fil.mkdirs();
File[] fi = f.listFiles();
for (File file : fi) {
if (file.isFile()) {
try {
BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(file));
int a;
File ff = new File(fil, file.getName());
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(ff));
while ((a = bis.read()) != -1) {
bos.write(a);
}
bos.close();
bis.close();
} catch (Exception e) {
e.printStackTrace();
}
} else {
copy(file, fil);
}
}
}
}
|