A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 黑铁太上皇 初级黑马   /  2019-8-1 16:02  /  669 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public static void main(String[] args) throws  IOException{
        File aa = new File("e:/111");
        File bb= new File("F:/");
        copydloe(aa,bb);
    }

    private static void copydloe(File aa, File bb) throws  IOException{
        String name = aa.getName();
        File cc =new File(bb,name);
        if(!cc.isDirectory()){
            cc.mkdir();
        }
        File[] files = aa.listFiles();
        for(File f:files){
            if(f.isDirectory()){
                copydloe(f,cc);
            }else {
                File ff=new File(cc,f.getName());
                copy(f,ff);
            }
        }
    }

    private static void copy(File f, File ff) throws  IOException {
        BufferedReader br =new BufferedReader(new FileReader(f));
        BufferedWriter bw = new BufferedWriter(new FileWriter(ff));
        String in ;
        while ((in = br.readLine())!=null){
            bw.write(in);
        }
        br.close();
        bw.close();
    }
}


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马