zoukankan      html  css  js  c++  java
  • 星涛:采用java递归复制文件夹

    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;
        }
    }
  • 相关阅读:
    浅拷贝和深拷贝问题
    指针遍历数组时用法
    一维数组和指针
    leetcode
    tmux
    git
    einsum详解
    spark快速大数据分析 读书笔记
    maven配置
    bash 学习笔记
  • 原文地址:https://www.cnblogs.com/botaoJava/p/13773259.html
Copyright © 2011-2022 走看看