import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Calendar; public class SendServer { private int num = ; public void process() { Calendar calendar = Calendar.getInstance();
String dir = calendar.get(Calendar.YEAR) + "" + getTimeString(calendar.get(Calendar.MONTH) + ""); String oldPath = "/img2" + dir;
String newPath = "/img5" + dir; try { while(true){
System.out.println("复制 " + oldPath + " 目录开始");
long t1 = System.currentTimeMillis(); num = ;
copyFolder(oldPath, newPath); long t2 = System.currentTimeMillis();
System.out.println("复制目录结束,用时:" + (t2-t1) + "ms,共复制:" + num + "文件");
} } catch (Exception ex) {
ex.printStackTrace();
}
} public void copyFolder(String oldPath, String newPath) { try {
File mFile = new File(newPath);
if(!mFile .exists()){
(new File(newPath)).mkdirs(); // 如果文件夹不存在 则建立新文件夹
}
File a = new File(oldPath);
String[] file = a.list();
File temp = null;
for (int i = ; 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()) {
String fileName = newPath + "/" + (temp.getName()).toString();
File testFile = new File(fileName);
if (!testFile.exists()) {
FileInputStream input = new FileInputStream(temp);
FileOutputStream output = new FileOutputStream(fileName);
byte[] b = new byte[ * ];
int len;
while ((len = input.read(b)) != -) {
output.write(b, , len);
}
output.flush();
output.close();
input.close();
num++;
}
}
if (temp.isDirectory()) {// 如果是子文件夹
copyFolder(oldPath + "/" + file[i], newPath + "/" + file[i]);
}
}
} catch (Exception e) {
System.out.println("复制整个文件夹内容操作出错");
e.printStackTrace(); }
} private String getTimeString(String time){
if(time.length()<){
return "" + time;
}
else{
return time;
}
}
}

-----------------------2017/3/22---------------------------------------

获得文件夹下所有文件名

    public static class TreeNode {
/**节点名称**/
private String text;
/**节点路径**/
private String fileName;
/**子节点**/
private List<TreeNode> children = new ArrayList<TreeNode>();
} public static TreeNode readfile(TreeNode tn){
try { File file = new File(tn.fileName);
tn.text = file.getName();
if (!file.isDirectory()) {
//System.out.println(file.getName()); } else if (file.isDirectory()) {
String[] filelist = file.list();
for (int i = 0; i < filelist.length; i++) {
File readfile = new File(tn.fileName + "\\" + filelist[i]);
TreeNode tn1 = new TreeNode();
tn1.text = readfile.getName();
tn1.fileName = tn.fileName + "\\" + filelist[i];
if (!readfile.isDirectory()) {
tn.children.add(tn1);
} else if (readfile.isDirectory()) {
tn.children.add(readfile(tn1));
}
}
} } catch (Exception e) {
System.out.println("readfile() Exception:" + e.getMessage());
}
return tn;
} public static void main(String[] args){
TreeNode tn = new TreeNode();
tn.fileName = "C:\\Users\\42955\\Desktop\\文件夹\\软件";
readfile(tn);
System.out.println(tn);
System.out.println(tn.text);
}

java 把一个文件夹里图片复制到另一个文件夹里的更多相关文章

  1. SQL数据库中把一个表中的数据复制到另一个表中

    1.如果是整个表复制表达如下: insert into table1 select  * from table2 2.如果是有选择性的复制数据表达如下: insert into table1(colu ...

  2. 把一个List<T>的数据复制至另一个List<T>

    把一个数据集List<T>复制至到另一个数据集List<T>. 方法一,可以使用循环,然后把每一个T添加至另一个集合中去: public void ListDemo() { , ...

  3. Java将一个目录下的所有数据复制到另一个目录下

    /* 将"C:\\JavaProducts\\Source"下的所有数据复制到"C:\\Target"下 */ import java.io.*; public ...

  4. VMWare12虚拟机实现主客机间的文件拖拽(复制粘贴)和文件夹共享

    版本: 主机:Windows 7 64位旗舰版 虚拟机: VMWare 12 + Windows 7 64位旗舰版 VMWare pro 12 + Ubuntu16.04LTS 64位 注:由于VMW ...

  5. 用Java 实现一个表中的数据复制到另一个表中

    string sql = "insert into tbl1(s1,s2,s3) select t.t1,t.t2,t.t3 from tab2 t";再用jdbc或者hibern ...

  6. oracle怎么把一个用户下的表复制给另一个用户?(授予表权限)

    //把system读写权限 授权给scottselect 'Grant all on '||table_name||' to scott;' from all_tables where owner = ...

  7. Java以流的方式将指定文件夹里的.txt文件全部复制到另一文件夹,并删除原文件夹中所有.txt文件

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...

  8. Git学习:如何在Github的README.MD文件下添加图片

    格式如下: ![image](图片的绝对路径) 关于图片的绝对路径: 必须把图片上传到github的代码仓库里,再将其图片的网址复制到括号里才可以,不能够直接把图片复制到readme.md文件里面,这 ...

  9. 巧用 git rebase 将某一部分 commit 复制到另一个分支

    一.为什么需要将一个 commit 复制到其他分支上去呢? 在我们的实际开发的过程中,我们的项目中会存在多个分支. 在某些情况下,可能需要将某一个分支上的 commit 复制到另一个分支上去.   二 ...

随机推荐

  1. GitHub上新建或删除仓库Repository

    一:新建仓库 在首页的New Repository,点击进入页面,输入和项目同名的仓库名就可以了.

  2. 放弃OT了,找了个新框架ThinkCMF

    放弃OT了,找了个新框架ThinkCMF,感觉还不错,用用看. 选择OT的原因: 1. OT基于ThinkPHP 2. OT对ThinkPHP进行了封装,使得开发应用更加简单 3. yershop应用 ...

  3. 当struts遇上json,没爱了

    用过struts的人,或者用过spring MVC的人,都知道domain model接受参数是多么的方便,而且又有依赖注入,简直是自动拿参数,再自动帮你转成java bean,但是也有不足的地方 说 ...

  4. 阿里巴巴开源Weex 开发教程

    Weex 是什么 Weex是阿里发布的一款用WEB方式开发原生app的开源产品 Weex能够完美兼顾性能与动态性,让移动开发者通过简捷的前端语法写出Native级别的性能体验,并支持iOS.安卓.Yu ...

  5. Quartz.NET开源作业调度框架系列(五):AdoJobStore保存job到数据库

    Quartz.NET 任务调度的核心元素是 scheduler, trigger 和 job,其中 trigger(用于定义调度时间的元素,即按照什么时间规则去执行任务) 和 job 是任务调度的元数 ...

  6. 12款最佳的 WordPress 语法高亮插件推荐

    语法高亮工具增强了代码的可读性,美化了代码,让程序员更容易维护.语法高亮提供各种方式由以提高可读性和文本语境,尤其是对于其中可以结束跨越多个页面的代码,以及让开发者自己的程序中查找错误.在这篇文章中, ...

  7. 【小贴士】虚拟键盘与fixed带给移动端的痛!

    前言 今天来公司的主要目的就是研究虚拟键盘与fixed的问题,期间因为同事问起闭包与事件委托(阻止冒泡)相关问题,便穿插了一篇别的: [小贴士]工作中的”闭包“与事件委托的”阻止冒泡“,有兴趣的朋友可 ...

  8. swift学习笔记之-高级运算符

    //高级运算符 import UIKit /*高级运算符(Advanced Operators):位运算符.溢出运算符.优先级和结合性.运算符函数.自定义运算符 位运算符: 1.位运算符可以操作数据结 ...

  9. Node入门

    一 node定位 Node.js是一个事件驱动I/O服务端JavaScript环境,是一个基于Google的V8引擎的Chrome JavaScript 运行时建立的一个平台. 二 node安装 (1 ...

  10. 一款实用的viewer.js 图片相册

    Viewer.js 是一款强大的图片相册插件,像SNS交友网站一般都会用到点击缩略图,弹出层大图片,而且弹出层有多个控制按钮,比如放大缩小.旋转.撤回等,底部有缩略图列表可切换. 支持移动设备触摸事件 ...