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

    //文件夹复制
        public static boolean folderCopy(String oldName,String newName){
            File oldfile = new File(oldName);
            File newfile = new File(newName);
    
            if(!oldfile.exists())return false;
            if(!newfile.exists()){
                newfile.mkdirs();
            }
    
            for (String name:oldfile.list()){
                File file = new File(oldName+"/"+name);
                if(file.isDirectory()){
                    File subFile = new File(newName,name);
                    subFile.mkdir();
                    folderCopy(oldName+"/"+name,newName+"/"+name);
                }else{
                    fileCopy2BufferByte(oldName+"/"+name,newName+"/"+name);
                }
            }
            return true;
        }
    
        //字节流高效缓冲区文件复制
        public static void fileCopy2BufferByte(String oldFileName,String newFileName){
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            try{
                bis = new BufferedInputStream(new FileInputStream(oldFileName));
                bos = new BufferedOutputStream(new FileOutputStream(newFileName));
                byte[] bytes = new byte[1024];
                int len = -1;
                while ((len = bis.read(bytes))!=-1)bos.write(bytes,0,len);
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                try {
                    if(bis!=null)bis.close();
                    if(bos!=null)bos.close();
                }catch (IOException ee){
                    ee.printStackTrace();
                }
            }
        }
  • 相关阅读:
    Java EE 经验
    Java界面设计 Swing(1)
    Java开源库
    Java Abstract Class & Interface
    Selenium WebDriver Code
    Json在PHP与JS之间传输
    Live YUV420 和 OpenCV Mat 的互相转换
    Visual C++ 升级到 Visual Studio
    Sentiment Analysis resources
    C# XMLDocument
  • 原文地址:https://www.cnblogs.com/luoyunyong/p/8543167.html
Copyright © 2011-2022 走看看