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();

}

}

}

java递归复制文件夹的更多相关文章

  1. 星涛:采用java递归复制文件夹

    package com.botao; import java.io.*; /** * @author cbt28 */ public class FileUtil { public static St ...

  2. JAVA实现复制文件夹

    package com.filetest; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; impor ...

  3. PHP递归复制文件夹以及传输文件夹到其他服务器。

    项目中需要复制整个文件夹,有时候还需要将整个文件夹传输到远程服务器. 这里就要递归遍历整个文件夹了,想看递归遍历文件夹的代码. function deepScanDir($dir) { $fileAr ...

  4. java递归删除文件夹

    递归删除文件夹 public static void delete(File file) { if(!file.exists()){ return; } if(file.isFile() || fil ...

  5. node.js 递归复制文件夹(附带文件过滤功能)

    1.简介: 很简单,写了一个node操作文件的小脚本,主要实现对目标文件夹中内容的复制.还顺带一个按照文件夹或者文件名过滤的功能. 2.应用场景 适合基于 node 环境的项目,项目打包的时候,配合 ...

  6. java递归处理文件夹和文件

    import java.io.File; /** * 文件综合使用示例 */ public class FileDelete { public static void main(String[] ar ...

  7. C#递归复制文件夹

    /// <param name="sources">原路徑</param> /// <param name="dest">目 ...

  8. java递归实现文件夹文件的遍历输出

    学习java后对一个面试小题(今年年初在团结湖面试的一个题目) 的习题的编写. ''给你一个文件,判断这个文件是否是目录,是目录则输入当前目录文件的个数和路径,''' /** * @author li ...

  9. java基础 File 递归删除文件夹中所有文件文件夹 目录(包含子目录)下的.java文件复制到e:/abc文件夹中, 并统计java文件的个数

    File 递归删除文件夹中所有文件文件夹 package com.swift.kuozhan; import java.io.File; import java.util.Scanner; /*键盘录 ...

随机推荐

  1. TCP三次握手过程中涉及的队列知识的学习

    先上一张图 (图片来源:http://www.cnxct.com/something-about-phpfpm-s-backlog/) 如上图所示,这里有两个队列:syns queue(半连接队列): ...

  2. 目标检测 — two-stage检测

    目前主流的目标检测算法主要是基于深度学习模型,其可以分成两大类:two-stage检测算法:one-stage检测算法.本文主要介绍第一类检测算法,第二类在下一篇博文中介绍. 目标检测模型的主要性能指 ...

  3. PAT Advanced 1022 Digital Library (30 分)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  4. 版本问题---cuda和tensorflow的版本对应关系

    cuda和tensorflow的版本有对应关系 https://tensorflow.google.cn/install/source#linux

  5. ArrayList 和 Vector 的区别是什么?(未完成)

    ArrayList 和 Vector 的区别是什么?(未完成)

  6. D. Lakes in Berland (DFS或者BFS +连通块

    https://blog.csdn.net/guhaiteng/article/details/52730373 参考题解 http://codeforces.com/contest/723/prob ...

  7. 原生JS实现简单富文本编辑器

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 甘特图控件如何自定义绘图?DevExpress Winforms帮你忙

    DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅.美观且易于使用的应用程序.无论是Office风格的界面,还是分析处理大批量的业务数据,DevExpr ...

  9. http文件服务器上传与下载功能

    https://www.cnblogs.com/liferecord/p/4843615.html

  10. selenium web driver

    WebDriver 支持的浏览器 IE6-10 FireFox大部分版本 Chrome Safari Opera Andrioid 系统上的自带浏览器 IOS系统上自带浏览器 HtmlUnit的无界面 ...