zoukankan      html  css  js  c++  java
  • 【复制多级文件夹(复制指定目录下的内容到另一指定目录下)】

    package com.yjf.esupplier.common.test;
    
    import java.io.*;
    
    /**
     * @author shusheng
     * @description
     * @Email shusheng@yiji.com
     * @date 2018/12/8 14:34
     */
    public class CopyFolderDemo {
    
        public static void main(String[] args) throws IOException {
    
            File srcFile = new File("D:\JZ-FILES\jhcc\templet-assemble");
            File destFile = new File("D:\test");
            if(!destFile.exists()){
                destFile.mkdir();
            }
    
            copyFolder(srcFile,destFile);
        }
    
        private static void copyFolder(File srcFile, File destFile) throws IOException {
            if(srcFile.isDirectory()){
                File newFolder = new File(destFile,srcFile.getName());
                newFolder.mkdir();
    
                File[] fileArray = srcFile.listFiles();
                for(File file:fileArray){
                    copyFolder(file,newFolder);
                }
            }else{
                File newFile = new File(destFile,srcFile.getName());
                copyFile(srcFile,newFile);
            }
        }
    
        private static void copyFile(File srcFile, File newFile) throws IOException {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile));
    
            byte[] bys = new byte[1024];
            int len=0;
            while((len=bis.read(bys))!=-1){
                bos.write(bys);
            }
            bis.close();
            bos.close();
        }
    
    }
    终身学习者
  • 相关阅读:
    python函数--isalpha()方法
    python函数--isdigit()方法
    python函数--isalnum()方法
    python函数--range()方法
    python函数--len()方法
    python函数--介绍
    Linux命令总结--awk命令
    Linux命令总结--pwd命令
    Linux命令总结--rm命令
    Linux命令总结--cp命令
  • 原文地址:https://www.cnblogs.com/zuixinxian/p/10087861.html
Copyright © 2011-2022 走看看