java代码拷贝文件
来源:互联网 发布:软件行业人均销售额 编辑:程序博客网 时间:2024/06/05 05:21
package p333;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.List;public class PrintFileName {private static int copy_ok_count, copy_fail_count;private static String srcPathPrefix = "E:/rename", desPathPrefix = "E:/renameok/";private static String currentName;private static int printdotcnt;/** * 复制整个文件夹内容 * * @param newPath * String 复制后路径 如:f:/fqf/ff * @param oldPath * String 原文件路径 如:c:/fqf * @return boolean */public static void copyFolder(String newPath, String oldPath) {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()) {//过滤一些文件if ( temp.toString().endsWith(".rar") == true || temp.toString().endsWith(".tmp") == true) {continue;}DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(temp)));DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(newPath + "/" + (temp.getName()).toString())));byte b[] = new byte[4096];int length;while ((length = dis.read(b)) != -1) {dos.write(b, 0, length);}dos.flush();dos.close();dis.close();System.out.print(".");printdotcnt++;if (printdotcnt >= 80) {printdotcnt = 0;System.out.println();}} else if (temp.isDirectory()) {// 如果是子文件夹copyFolder(newPath + "/" + file[i], oldPath + "/" + file[i]);}}} catch (Exception e) {System.out.println("复制整个文件夹内容操作出错");e.printStackTrace();}}public static void main(String[] args) {String startTime;SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式File file = new File(srcPathPrefix);copy_ok_count = 0;copy_fail_count = 0;printdotcnt = 0;startTime = "\n开始时间:" + df.format(new Date());// Date()为获取当前系统时间copyFolder(desPathPrefix, srcPathPrefix);System.out.println(startTime);System.out.println("结束时间:" + df.format(new Date()));System.out.println("\nall file copy over!");}}
阅读全文
0 0
- java拷贝文件代码
- java代码拷贝文件
- 过虑文件拷贝文件的java代码
- 多线程下载,拷贝文件java代码
- Java实现拷贝文件详细代码
- Java中 文件拷贝代码模型
- python文件拷贝代码
- C++文件拷贝代码
- 拷贝文件代码
- 拷贝文件经典代码
- 拷贝文件代码
- java 文件夹拷贝(文件夹里包含文件和文件夹) 代码
- java 文件夹拷贝(文件夹里包含文件和文件夹) 代码
- Java代码拷贝对应的文件到指定目录
- java 文件夹拷贝(文件夹里包含文件和文件夹) 代码
- java文件拷贝
- Java拷贝文件
- java实现文件拷贝
- PostgreSQL数据库从入门到精通
- 温故知新 Java基础(二)
- 关于长尾应用的一些思考
- 3D数学基础---矩阵旋转
- APP从启动到主页面显示
- java代码拷贝文件
- Oracle 之 存储过程|程序包|触发器|视图|同义词
- Android 恢复出厂设置流程分析
- C++11 并发指南七(C++11 内存模型一:介绍)
- HDU 6136 Death Podracing(优先队列+双向链表)
- ionic2 安装教程
- xml的优点
- Infrastructure(基础型)网络的电源管理
- TCP/IP--网际协议IP