• 文件与文件夹的拷贝



    //
    文件拷贝---------------------------------------------------------------------------- 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())); } } } }
  • 相关阅读:
    win10安装virtualBox创建CentOS6.5虚拟机
    ES系列二、CentOS7安装ES head6.3.1
    ES系列一、CentOS7安装ES 6.3.1、集成IK分词器
    Python easyGUI 猜数字
    Python easyGUI 登录框 非空验证
    Python easyGUI 文件浏览 显示文件内容
    Python easyGUI 文件对比 覆盖保存
    Python 统计代码量
    什么是一个人真正的魅力?
    Python学习笔记(15)- osos.path 操作文件
  • 原文地址:https://www.cnblogs.com/king-/p/4389681.html
Copyright © 2020-2023  润新知