- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- //"基础班第一次班会资料"---> Copy
- public class BigTestDemo {
- public static void main(String[] args) throws IOException {
- File srcPath = new File("基础班第一次班会资料");
- File destPath = new File("Copy");
-
- copyMothed(srcPath,destPath);
- }
- private static void copyMothed(File srcPath,File destPath) throws IOException {
- destPath.mkdir();
- File[] file = srcPath.listFiles();
- for (File file2 : file) {
- if (file2.isDirectory()){
- File dest = new File(destPath, file2.getName());
- copyMothed(file2, dest);
- }else {
- File dest = new File(destPath,file2.getName());
- copy(file2,dest);
- }
- }
-
- }
- private static void copy(File file2, File dest) throws IOException {
- FileInputStream fis = new FileInputStream(file2);
- FileOutputStream fos = new FileOutputStream(dest);
- int ch = -1;
- while((ch = fis.read()) != -1){
- fos.write(ch);
- }
- fis.close();
- fos.close();
- }
- }
复制代码 |