- 浏览: 237342 次
- 性别:
- 来自: 上海
-
最新评论
-
iwindyforest:
pinocchio2mx 写道iwindyforest 写道H ...
VMware Workstation 11 或者 VMware Player 7安装MAC OS X 10.10 Yosemite -
nng119:
找不到设备的安装信息 这个问题怎么解决的?
VMware Workstation 11 或者 VMware Player 7安装MAC OS X 10.10 Yosemite -
pinocchio2mx:
iwindyforest 写道Hi pinocchio2mx ...
VMware Workstation 11 或者 VMware Player 7安装MAC OS X 10.10 Yosemite -
iwindyforest:
Hi pinocchio2mx 兄弟, 这个镜像是好的, 我安 ...
VMware Workstation 11 或者 VMware Player 7安装MAC OS X 10.10 Yosemite -
pinocchio2mx:
蛋疼啊,折腾一晚上还没搞定!网上的教程没一篇靠谱的,摸摸索索到 ...
VMware Workstation 11 或者 VMware Player 7安装MAC OS X 10.10 Yosemite
package com.iwindyforest.dir; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; public class FileSystem { private ArrayList<String> fileList = new ArrayList<String>(); public FileSystem(String path) { long a = System.currentTimeMillis(); this.listFiles(path); this.print("TimeCost:" + (System.currentTimeMillis() - a) + " Millis"); this.xCopy(path, "C:\\temp"); } private void print(String message) { System.out.println(message); } public void listFiles(String strPath) { File dir = new File(strPath); if(dir != null && dir.exists()) { if(dir.isDirectory()) { File[] files; try { files = dir.listFiles(); } catch(SecurityException e) { files = null; e.printStackTrace(); } if(files == null) { return; } else { for(int i = 0; i < files.length; i++) { String strFileName = files[i].getAbsolutePath(); if(files[i].isDirectory()) { this.print("D--:" + strFileName); this.listFiles(files[i].getAbsolutePath()); } else { this.print("F--:" + strFileName); fileList.add(files[i].getAbsolutePath()); } } } } else { this.print("F--:" + dir.getAbsolutePath()); } } else { this.print("FileNotExist:" + dir.getAbsolutePath()); } } private boolean checkDir(File dir) { if(dir == null) { this.print("dirPath is null"); return false; } else if(!dir.exists()) { this.print("dirPath: " + dir.getAbsolutePath() + " doesn't exist."); return false; } else if(!dir.isDirectory()) { this.print("dirPath: " + dir.getAbsolutePath() + " is not a directory."); return false; } else { return true; } } /** * 类似与windows操作系统的xCopy,递归拷贝整个源目录到目标目录。 源目录和目标目录必须已经存在。 * * @param srcDirPath * @param destDirPath */ public void xCopy(String srcDirPath, String destDirPath) { File srcDir = new File(srcDirPath); File destDir = new File(destDirPath); if(this.checkDir(srcDir) && this.checkDir(destDir)) { File[] files; try { files = srcDir.listFiles(); } catch(SecurityException e) { files = null; this.print("xCopy breaked: can't listFiles,may be caused by:"); e.printStackTrace(); return; } if(files == null) { return; } else { for(int i = 0; i < files.length; i++) { String fileName = files[i].getName(); String absoluteFileName = files[i].getAbsolutePath(); if(files[i].isDirectory()) { // 下一次递归的源目录 String subSrcDir = srcDir.getPath() + File.separator + fileName; // 下一次递归的目的目录 String subDestDir = destDir.getPath() + File.separator + fileName; try { new File(subDestDir).mkdir(); } catch(SecurityException e) { this.print("can't mkdir in path : " + subDestDir); this.print("xCopy breaked cause by: "); e.printStackTrace(); return; } xCopy(subSrcDir, subDestDir); } else { String destFileName = destDirPath + File.separator + fileName; copyFile(absoluteFileName, destFileName); } } } } } /** * 简单复制单个文件到目标路径。目标路径下的该文件必须有可写权限 * * @param srcFilePath * @param desFilePath */ public void copyFile(String srcFilePath, String desFilePath) { int byteread = 0; InputStream in = null; FileOutputStream out = null; try { in = new FileInputStream(srcFilePath); out = new FileOutputStream(desFilePath); } catch(FileNotFoundException e) { e.printStackTrace(); } byte[] buffer = new byte[1024]; try { while((byteread = in.read(buffer)) != -1) { out.write(buffer, 0, byteread); } in.close(); out.close(); } catch(IOException e) { e.printStackTrace(); } } public static void main(String[] args) { if(args.length == 1) { new FileSystem(args[0]); } else { new FileSystem(System.getProperty("user.dir", "c:\\")); } } }
- xcopy.rar (7.5 KB)
- 描述: java xCopy源代码
- 下载次数: 58
评论
2 楼
iwindyforest
2008-07-10
哦,谢谢EXvision的指点!
commons的FileUtils还没看到,所以不知道,
回去好好看下...
commons的FileUtils还没看到,所以不知道,
回去好好看下...
1 楼
EXvision
2008-07-09
很销魂的轮子哦.
commons的FileUtils貌似帮lz写好了这些。
commons的FileUtils貌似帮lz写好了这些。
发表评论
-
利用归并排序算法对大文件进行排序
2015-01-25 20:59 5657归并排序算法介绍,请参照Wikipeida zh. ... -
try-catch影响性能吗?
2014-07-09 17:06 1708try-catch会影响性能吗? try-catch放在循 ... -
Java Concurrency In Practice Learning Note
2014-06-17 11:13 0Frameworks introduce concurre ... -
Java collections overview
2014-03-21 10:37 886Fromp: http://java-performance ... -
JVM Learning Note 4 -- HotSpot JVM Options List
2014-02-26 11:08 1043From: http://www.oracle.c ... -
Eclispe 性能优化
2014-02-25 15:07 962我目前Eclipse所在的机器环境是windows x32 ... -
JVM Learning Note 3 -- JVM Performance Monitor Tools
2014-02-25 12:25 1188JDK Provided Tools Comman ... -
JVM Performance Monitor Tools
2014-02-25 11:12 5JDK Provide Tools Command Li ... -
JVM Learning Note 2 -- Garbage Collection and Memory Allocation Strategy
2014-02-18 14:57 1776Method to check if an object ... -
JVM Learning Note 1 -- Run-Time Data Areas and Object Representation
2014-02-11 00:44 894Run-Time Data Areas Clas ... -
String.intern()方法
2014-02-10 16:22 800intern public String intern() ... -
GlobalKnowledge: 2013 IT 技能薪水报告
2014-01-09 18:24 1889from: GlobalKnowledge http:/ ... -
OLTP Vs OLAP
2014-01-02 13:42 851OLTP vs. OLAP We can divide ... -
java的字符串拼接
2013-12-31 16:43 828每当我用+运算符拼接字符串时, 总有人跟我提出你应该 ... -
45 Useful JavaScript Tips, Tricks and Best Practices
2013-12-31 11:08 10236By Saad Mousliki ... -
面试10大算法汇总+常见题目解答
2013-12-16 18:03 2018面试10大算法汇总+常见题目解答 最近更新 ... -
面试关于HashMap的工作原理
2013-12-16 17:58 1992先来些简单的问题 “你用过HashMap吗?” ... -
处理 InterruptedException
2013-11-01 16:28 758这样的情景您也许并不陌生:您在编写一个测试程序,程序需要暂 ... -
Java正确处理InterruptedException的方法
2013-11-01 16:24 814要想讨论正确处理Interr ... -
Overview To CMMI v1.3
2013-07-05 18:15 927What is CMMI? CMMI® (Capa ...
相关推荐
Windows操作系统中,虽然图形化界面更常见,但命令提示符CMD或PowerShell同样有用。比如`dir`相当于Linux的`ls`,`copy`或`xcopy`用于复制文件,`del`对应删除文件,`cd`同样用于切换目录。 在数据库管理方面,粟...
在Windows系统中,我们可以使用`xcopy`命令配合通配符来实现。例如,如果我们有一个名为`example.txt`的文件,想将其复制到`C:\MyDirectory`及其所有子目录中,可以运行以下命令: ```cmd xcopy C:\MyDirectory\...
批处理脚本是一种在Windows操作系统环境下执行的一系列命令行指令的集合,主要用于自动化日常任务,如文件管理、系统维护和程序执行。它使用简单的文本编辑器编写,扩展名为.bat或.cmd,通过DOS命令行环境运行。...
DOS(Disk Operating System)是早期个人计算机上广泛使用的操作系统,它使用命令行界面来执行各种操作。虽然现在许多用户更倾向于图形化界面,但了解DOS命令仍然对理解计算机操作原理和进行系统管理有重要作用。这...
### CMD命令大全:掌握...以上命令只是CMD命令行接口中的一部分,它们为用户提供了一个强大的工具集,可以进行系统管理、文件操作、自动化任务以及故障排除。掌握这些命令,将极大地提升你在IT领域的技能和效率。
2.1.3 .NET与Java 有些类似 .......... 21 2.1.4 现在所处的阶段 .................... 22 2.2 为Windows 编写软件 ............... 22 2.2.1 .NET Framework类 ............... 23 2.2.2 执行代码 .......