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. Linux服务器centos7系统下搭建Jenkins

    Jenkins是什么? Jenkins是开源CI&CD软件领导者, 提供超过1000个插件来支持构建.部署.自动化, 满足任何项目的需要. 所以现在是越来越多的公司都在使用Jenkins做持续 ...

  2. zabbix-将业务机器加入到监控中

    一.设置被监控的机器 1. 配置主机名 echo "agent.test.com" > /etc/hostname hostname agent.test.com 2.安装z ...

  3. Mysql中的锁机制-转载

    原文:http://blog.csdn.net/soonfly/article/details/70238902 锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的 计算资源(如 ...

  4. Visual Studio 2017使用

    常用快捷方式 Ctrl + KK插入书签 取消书签Ctrl + KP 上一个书签Ctrl + KN 下一个数千Ctrl + F3 先一个关键词Shift + F3 上一个关键词 Ctrl + KC 添 ...

  5. 解决Centos /boot过小无法更新内核

    Centos7默认安装时,/boot目录设置只有150M左右,这样编译几个版本的内核/boot空间就不够用了.报错大致如下: Disk Requirements: At least 3MB more ...

  6. test11111111

    test 博文内容中字符过多,拒绝显示 123123123

  7. @@identity, scope_identity ident_current 的区别

  8. MySQL 进阶3 排序查询

    #进阶3 排序查询 格式: select 查询列名 from 表 [where 筛选条件] order by 排序列名 [asc / desc] 排序查询/嵌套排序查询/函数查询/[按别名进行 排序] ...

  9. idea maven配置

    转载自:https://www.cnblogs.com/Silencepeng/p/7444012.html 一.下载maven的包 http://www.apache.org/ 1.在网页中打开上面 ...

  10. Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation '<>'

    1.问题 今天又在mysql中遇到了,吐血. 2.解决方案 SQL最后加上 COLLATE utf8mb4_unicode_ci SELECT t2.cust_id as cust_id_ex,t1. ...