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. hibernate----component-entity (人-地址-学校)

    package com.ij34.dao; import javax.persistence.*; @Entity @Table(name="school_inf") public ...

  2. ListView 下拉更新 (支持 Android)

    注意:XE7 已提供下拉更的功能. 说明:展示如何在 Android 平台下,使用 ListView 下拉更新. 适用:Delphi XE5 , XE6 修改:需要修改到 Delphi 源码 FMX. ...

  3. 安装Sublime Text 3汉化插件

    一.Sublime Text工具介绍: Sublime Text 是一个代码编辑器(Sublime Text 2是收费软件,但可以无限期试用),也是HTML和散文先进的文本编辑器.Sublime Te ...

  4. Scalaz(19)- Monad: \/ - Monad 版本的 Either

    scala标准库提供了一个Either类型,它可以说是Option的升级版.与Option相同,Either也有两种状态:Left和Right,分别对应Option的None和Some,不同的是Lef ...

  5. js undefine,null 和NaN

    undefined 类型只有一个值,即 undefined. null 类型也只有一个值,即 null. null 指空值(empty value)或指曾赋过值,但是目前没有值 undefined 指 ...

  6. 高性能 Windows Socket 组件 HP-Socket v2.3.1-beta-1 发布

    HP-Socket 是一套通用的高性能 Windows Socket 组件包,包含服务端组件(IOCP 模型)和客户端组件(Event Select 模型),广泛适用于 Windows 平台的 TCP ...

  7. Foreach原理

    本质:实现了一个IEnumerable接口, 01.为什么数组和集合可以使用foreach遍历? 解析:因为数组和集合都实现了IEnumerable接口,该接口中只有一个方法,GetEnumerato ...

  8. 小白linux安装php 5.6+nginx配置(踩坑版)

    因为要搭建个知识库,直接用wordpress,这前提是得先装php,实在不喜欢XAMPP,所以自己折腾,没想到php这一来还不少啊,从头到尾折腾了一个小时多.记录下主要的流程和遇到的坑. 首先官网下载 ...

  9. 如何去除My97 DatePicker控件上右键弹出官网的链接 - 如何debug混淆过的代码

    概述 http://my97.net/是一个web浏览器的日期选择控件,非常好用,做得非常棒,各种API等事件等都很方便,但是使用了4.8beta3之后,在控件上面右击会出现官网链接 ,这个是PM以及 ...

  10. Immutable.js – JavaScript 不可变数据集合

    不可变数据是指一旦创建就不能被修改的数据,使得应用开发更简单,允许使用函数式编程技术,比如惰性评估.Immutable JS 提供一个惰性 Sequence,允许高效的队列方法链,类似 map 和 f ...