zoukankan      html  css  js  c++  java
  • 复制多级文件夹

    package com.io.liushuaishuai;
    
    import java.io.*;
    
    public class copyFolderDemo01 {
        public static void main(String[] args)throws IOException {
            //创建数据源File对象,路径是c:\java
            File srcfile = new File("c:\java");
            //创建目的地File对象,路径是c:\F
            File destfile = new File("c:\F");
    
            //文件夹复制
            copyFolder(srcfile, destfile);
    
    
        }
    
        private static void copyFolder(File srcfile, File destfile)throws IOException {
            if (srcfile.isDirectory()) {
                String srcfileName = srcfile.getName();
                File newFolder = new File(destfile, srcfileName);
                if (!newFolder.exists()) {
                    newFolder.mkdir();
                }
                File[] filearray = srcfile.listFiles();
                for (File file : filearray) {
                    copyFolder(file, destfile);
                }
            } else {
                copyFile(srcfile, new File(destfile, srcfile.getName()));
            }
    
        }
    
        private static void copyFile(File srcfile, File destfile) throws IOException {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcfile));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destfile));
    
            byte[] bys = new byte[1024];
            int len;
            while ((len=bis.read(bys))!=-1) {
                bos.write(bys,0,len);
            }
            bis.close();
            bos.close();
        }
    }
    
  • 相关阅读:
    【译】NodeJS and Good Practices
    【译】单一责任原则
    CSS 属性 z-index
    Node 连接 MySql
    CentOS 7 后台克隆远程库
    H5log打印
    利用Promise实现Promise.all
    Set、Map、WeakSet、WeakMap 理解与使用
    vue如何禁止弹窗后面的滚动条滚动?
    vue面试题总结
  • 原文地址:https://www.cnblogs.com/lsswudi/p/11429606.html
Copyright © 2011-2022 走看看