package com.haiyisoft.hyoaService;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/copy")
public class CopyFolderController {

//http://localhost:6011/hyoaservice/copy/exec.do
@RequestMapping(value="/exec")
@ResponseBody
public void upload(String oldPath, String newPath) {

copyFolder( "F://cc", "E://cc");

}

private void copyFolder(String oldPath, String newPath) {
// TODO Auto-generated method stub
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()){
BufferedInputStream input = new BufferedInputStream (new FileInputStream(temp));

BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(newPath + "/" + (temp.getName()).toString()));
byte[] bytes=new byte[1024];
int len=0;
while ( (len = input.read(bytes)) != -1) {
output.write(bytes,0,len);

}

output.flush();
input.close();
}
if(temp.isDirectory()){//如果是子文件夹
copyFolder(oldPath+"/"+file[i],newPath+"/"+file[i]);
}
}
}
catch (Exception e) {
System.out.println("复制整个文件夹内容操作出错");
e.printStackTrace();

}

}

}

最新文章

  1. HTML5 Canvas彩色小球碰撞运动特效
  2. webapi修改tt模板给字段添加JsonIgnore特性解决转换json循环引用问题
  3. CSS3选择器——基本选择器
  4. 强大的windbg定位内存泄露,两句命令搞定!
  5. svn server
  6. JAVA学习中Swing概述中的JFrame学习
  7. 学习总结 java 异常
  8. 必须会的SQL语句(一) 创建数据库与删除数据库
  9. maven系列(1)-maven的介绍与安装
  10. Winform的窗体美化心酸路
  11. easyui表单提交,后台获取不到值
  12. 使用Fiddler提高前端工作效率 (介绍篇)
  13. [转] splice系列系统调用
  14. hdu 确定比赛名次
  15. C# The process cannot access the file because it is being used by another process
  16. js 将一大段时间均分为很多个小时间段
  17. 用tortoiseGit管理GitHub项目代码(完整教程)
  18. 1052. Linked List Sorting (25)
  19. thymeleaf学习笔记
  20. Go Example--格式化字符串

热门文章

  1. liunx shell 脚本的基础知识
  2. Java之IO学习
  3. Linux学习笔记(六)Linux常用命令:关机、重启以及系统运行级别
  4. Ubuntu系统---安装“搜狗拼音法”导致桌面打不开
  5. Ubuntu系统---安NVIDIA 驱动后 CUDA+cuDNN 安装
  6. LINQ图解教程
  7. MySQL中的with rollup的作用
  8. node.js中允许的app对象声明方式
  9. Java8-ConcurrentHashMap
  10. Node.js 调试小技巧