file文件复制
来源:互联网 发布:淘宝售后退款不提醒 编辑:程序博客网 时间:2024/05/16 11:18
/** * 复制单个文件 * @param oldPath String 原文件路径 如:c:/fqf.txt * @param newPath String 复制后路径 如:f:/fqf.txt * @return boolean */ public void copyFile(String oldPath, String newPath) { try { int bytesum = 0; int byteread = 0; File oldfile = new File(oldPath); if (oldfile.exists()) { //文件存在时 InputStream inStream = new FileInputStream(oldPath); //读入原文件 FileOutputStream fs = new FileOutputStream(newPath); byte[] buffer = new byte[1444]; int length; while ( (byteread = inStream.read(buffer)) != -1) { bytesum += byteread; //字节数 文件大小 System.out.println(bytesum); fs.write(buffer, 0, byteread); } inStream.close(); } } catch (Exception e) { System.out.println("复制单个文件操作出错"); e.printStackTrace(); } } /** * 复制整个文件夹内容 * @param oldPath String 原文件路径 如:c:/fqf * @param newPath String 复制后路径 如:f:/fqf/ff * @return boolean */ public void copyFolder(String oldPath, String newPath) { try { (new File(newPath)).mkdirs(); //如果文件夹不存在 则建立新文件夹 File a=new File(oldPath); String[] file=a.list(); File temp=null; for (int i = 0; i < file.length; i++) { if(oldPath.endsWith(File.separator)){ temp=new File(oldPath+file[i]); } else{ temp=new File(oldPath+File.separator+file[i]); } if(temp.isFile()){ FileInputStream input = new FileInputStream(temp); FileOutputStream output = new FileOutputStream(newPath + "/" + (temp.getName()).toString()); byte[] b = new byte[1024 * 5]; int len; while ( (len = input.read(b)) != -1) { output.write(b, 0, len); } output.flush(); output.close(); input.close(); } if(temp.isDirectory()){//如果是子文件夹 copyFolder(oldPath+"/"+file[i],newPath+"/"+file[i]); } } } catch (Exception e) { System.out.println("复制整个文件夹内容操作出错"); e.printStackTrace(); } }
0 0
- file文件复制
- File文件递归复制
- Java File创建文件复制文件
- Java中的File类 读写复制文件
- java移动/复制文件 copy/move file
- File类:文件的删除和复制
- file复制
- File复制
- File,FileInputStream,FileOutputStream以及一个复制文件的例子。
- File,FileInputStream,FileOutputStream以及一个复制文件的例子
- Java: File copy in Java – Benchmark(Java文件复制)
- 【Java】File类文件管理及IO读写、复制操作
- Android 复制单个文件到指定目录,Android copy file
- file 文件的操作 移动 、删除 、复制 操作
- Linux 复制文件报 not a regular file
- File操作-使用NIO进行文件的读写与复制
- File操作(4)-----文件复制(一)
- File操作(5)---------文件读取,写入 复制(二)
- hdu1160简单dp最长下降子序列
- Word怎么能有效转换成PDF格式
- 黑马程序员--java基础--网络编程(UDP和TCP)
- 由于检索用户的本地应用程序数据路径时出错,导致无法生成 SQL Server 的用户实例。解决方案
- 机器学习&数据挖掘笔记_16(常见面试之机器学习算法思想简单梳理)
- file文件复制
- CoreText实现图文混排
- Doxygen简介
- Android开发教程--关于Adapter的The content of the adapter has changed问题分析
- Linux复习(六)
- 关于安卓visualizer的用法
- 信息系统开发中常用的需求获取方法和技术
- virtualbox无法创建64虚拟机的解决办法
- 使用MKL求解矩阵的行列式值与逆