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. 修复 XE8 FMX Windows 列印旋转文字问题

    问题:XE8 Firemonkey Windows 无法列印旋转文字(与显示在视窗里的代码相同时) 适用:XE8 Windows 平台(其它平台测试没问题) 修复前效果: 修复后效果: 修复方法: 请 ...

  2. Bash中的任务(job)管理

    本来不准备写这篇博客的,因为任务管理(job管理)非常非常常用,以至于觉得根本没有必要去写这样一个东西.但想了下,还是记录一下吧,也许有人会用到呢. 不知你是否碰到过这样的情况,当你兴致勃勃的打开VI ...

  3. WinForm 窗体应用程序 (初步)之二

    现在,我们来了解一些基本控件.控件是放置在工具箱里的,你可以在界面的左侧或者通过菜单栏的视图选项找到它. (1)Label 控件 这是一个用于放置文字的控件,因为你不能在窗体上直接输入文字. (2)T ...

  4. 解决MVC4发布在IIS7后,路径无法访问.apk文件的解决方法

    随着智能手机的普及,越来越多的人使用手机上网,很多网站也应手机上网的需要推出了网站客户端,.apk文件就是安卓(Android)的应用程序后缀名,默认情况下,使用IIS作为Web服务器的无法下载此文件 ...

  5. linux常用命令之压缩打包

    DF df – report file system disk space usage 查看文件系统的使用清空 用法 df [-hi] [path] 选项 -h human readable ,以人类 ...

  6. 代码验证浏览器是否支持html audio 和video

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  7. Dynatable – 基于 HTML5 & jQuery 的交互表格插件

    Dynatable 一款有趣的,语义化,交互式的表格插件,使用 jQuery,HTML5 和 JSON 实现.Dynatable 的目的是提供一种简单的.可扩展的 API,能够轻松的浏览和操作大规模的 ...

  8. Java2_J2EE体系架构

    J2EE是Java2平台企业版(Java 2 Platform,Enterprise Edition),它的核心是一组技术规范与指南,提供基于组件的方式来设计.开发.组装和部署企业应用.J2EE使用多 ...

  9. 异常之JSP页面跳转出错

    今天在开发过程中发现一个问题:在页面中使用了<jsp:forward>抛错Attempt to clear a buffer that's already been flushed!! 百 ...

  10. 一级缓存、二级缓存、延迟加载、hibernate session 域 pojo三种状态

    1.一级缓存(session缓存 ).二级缓存      意义:提高hibernate查询效率.    缺点:可能会因并发,产生数据不一致.      本质:基于session 的缓存,利用hiber ...