zoukankan      html  css  js  c++  java
  • 文件与文件夹的拷贝


    //
    文件拷贝---------------------------------------------------------------------------- public void copyFile(File src_, File dest_) { File src = src_;//源文件 File destination = dest_;//目的地 if(!src.isFile()) { new Exception("ssssssss"); } InputStream is = null; OutputStream os = null; try { is = new FileInputStream(src); os = new FileOutputStream(destination,true);//true是可以继续写,flase则覆盖 byte[] flush = new byte[1024]; int len; while(-1!=(len=is.read(flush))) { os.write(flush, 0, flush.length); } os.flush();//记得手动flush一下 } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if(null!=os) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } if(null!=is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } } //文件夹拷贝------------------------------------------------------------- public class DirCopy { public static void main(String[] args) { String srcPath = "d:/javac/bb"; String destPath = "d:/javac/aa"; File src = new File(srcPath); File dest = new File(destPath); if(src.isDirectory()) { dest = new File(destPath, src.getName()); } copyDirDetil(src,dest); } private static void copyDirDetil(File src, File dest) { if(src.isFile()) { FileCopy fc = new FileCopy(); fc.copyFile(src, dest); } else if(src.isDirectory()) { dest.mkdirs(); for(File temp : src.listFiles()) { copyDirDetil(temp, new File(dest, temp.getName())); } } } }
  • 相关阅读:
    代码控制数据流量开关
    用wifi来调试应用程序
    详细解读LruCache类
    修改博客园默认的代码字体大小
    通过Gson解析Json数据
    Docker、Kubernetes的 CICD实现思路
    React中路由传参及接收参数的方式
    微信小程序开发工具调试没问题,真机调试Provisional headers are shown
    物联网卡三码
    【微信开发】-- 企业转账到用户
  • 原文地址:https://www.cnblogs.com/king-/p/4389681.html
Copyright © 2011-2022 走看看