package com.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

public class CopyFile {

public static void main(String[] args) throws IOException {
// Scanner sc = new Scanner(System.in);
// System.out.println("请输入源目录:");
// String sourcePath = sc.nextLine();
// System.out.println("请输入新目录:");
// String path = sc.nextLine();
//
String sourcePath = "D:/test/A";
String newPath = "D:/test/B";

copyDir(sourcePath, newPath);
}

public static void copyDir(String sourcePath, String newPath) throws IOException {
File file = new File(sourcePath);
String[] filePath = file.list();

if (!(new File(newPath)).exists()) {
(new File(newPath)).mkdir();
}

for (int i = 0; i < filePath.length; i++) {
if ((new File(sourcePath + file.separator + filePath[i])).isDirectory()) {
copyDir(sourcePath + file.separator + filePath[i], newPath + file.separator + filePath[i]);
}

if (new File(sourcePath + file.separator + filePath[i]).isFile()) {
copyFile(sourcePath + file.separator + filePath[i], newPath + file.separator + filePath[i]);
}

}
}
public static void copyFile(String oldPath, String newPath) throws IOException {
File oldFile = new File(oldPath);
File file = new File(newPath);
FileInputStream in = new FileInputStream(oldFile);
FileOutputStream out = new FileOutputStream(file);;

byte[] buffer=new byte[2097152];
int readByte = 0;
while((readByte = in.read(buffer)) != -1){
out.write(buffer, 0, readByte);
}

in.close();
out.close();
}

}

最新文章

  1. [版本管理]有惊无险修复svn服务器Invalid filesystem revision number问题
  2. openldap复制
  3. LevelDB(v1.3) 源码阅读之 Arena(内存管理器)
  4. 基于Spring框架的Web应用开发笔记 - Outline
  5. IIS负载均衡相关
  6. Setup a private http/nginx based GIT server
  7. 浅谈如何让 Bootstrap 3兼容IE8浏览器
  8. java集合练习
  9. bzoj:1457: 棋盘游戏
  10. python arvg用法
  11. NancyFX 第五章 Nancy 路由
  12. 【IOS 开发】Object - C 语法 之 流程控制
  13. Centos6.5DRBD加载失败,系统更换yum源(国内163)
  14. 如何用cmake编译
  15. git 提交代码操作
  16. LeetCode算法题-Two Sum II - Input array is sorted
  17. How to create an rpm package
  18. 手机CPU天梯图2018年5月最新版
  19. TestNG参数
  20. Centos7初次开机提示Initial setup of CentOS Linux 7 (core)

热门文章

  1. Java操作文件那点事
  2. maven项目无法查看类库的源码
  3. csp-s模拟106
  4. 设置django 时间
  5. SQL-W3School-高级:SQL DEFAULT 约束
  6. centos6.5安装mysql(转载,亲测可用)
  7. 使用Python处理Excel表格的简单方法
  8. Generate Maximum revenue by selling K tickets from N windows
  9. 【ARTS】01_29_左耳听风-201900527~201900602
  10. SpringBoot: 10.整合mybatis(转)