package FileCopy;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileCopy3 {
public static void main(String[] args) {
File f1 = new File("D:\\360bizhi\\wallpaperhelper");
File f2 = new File("j:\\");
try {
copy(f1, f2);//--------------------------------------------------13行
} catch (IOException e) {
e.printStackTrace();
}
}
private static void copy(File f1, File f2) throws IOException {
f2 = new File(f2, f1.getName());
if (f2.exists()) {
f2.mkdir();
}
File[] lf = f1.listFiles();
for (File file : lf) {
if (file.isFile()) {
FileInputStream is = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(new File(f2, file.getName()));// 28行
byte[] bt = new byte[1024];
int len = 0;
while ((len = is.read(bt)) != -1) {
fos.write(bt, 0, len);
}
is.close();
fos.close();
} else if (file.isDirectory()) {
copy(file, f2);
}
}
}
}
|
|