botaoJava
package com.botao;

import java.io.*;

/**
 * @author cbt28
 */
public class FileUtil {
    public static String a="";
    public static String b="";

    public static void copyDir(File src, File target) throws IOException {
        if (!target.exists()) {
            target.mkdir();
        }
        File[] lf = src.listFiles();
        for (File file : lf) {
            if (file.isFile()) {
                System.out.println(src + "\\" + file.getName() + "--->" + target + "\\" + file.getName());
                boolean b = copyFile(new File(src + "\\" + file.getName()), new File(target + "\\" + file.getName()));
                System.out.println(b);
            } else {
                copyDir(new File(src + "\\" + file.getName()), new File(target + "\\" + file.getName()));
            }
        }
    }

    public static boolean copyFile(File src, File target) throws IOException {
        FileReader fr = new FileReader(src);
        BufferedReader br = new BufferedReader(fr);

        FileWriter fw = new FileWriter(target);
        BufferedWriter bw = new BufferedWriter(fw);
        String s = br.readLine();
        while (s != null) {
            bw.write(s);
            bw.newLine();
            s = br.readLine();
        }
        bw.close();
        fw.close();
        br.close();
        fr.close();
        return true;
    }
}

分类:

java

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
猜你喜欢
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-10-17
相关资源
相似解决方案