Free Java Utility To Touch Files (Cross Platform) 免费的Java工具来触摸文件(跨平台)
This is a simple commandline Java utility which I wrote down in under 5 minutes to help in checking-in (svn commit) over 500 files which were modified but the dates weren't changed due to an error in our settings.这是一个简单的命令Java的实用工具,我写下下,在5分钟,以帮助在办理登机手续,在( svn承诺)超过500个文件被修改,但是日期不改变,因为一个错误,在我们的设置。 So subversion failed to recognize it.因此,颠覆未能认识到它。 Anyway this simple utility updates the timestamp of any file(s) and directories recursively to current time .无论如何,这个简单的实用程序更新的时间戳的任何文件( S )和目录递归,以当前时间 。 It is extremely fast and cross-platform.这是非常快速和跨平台。 It does one job and does it well.但这一份工作是否良好。 It is named after the unix utility touch , with similar functionality.这是命名后的Unix实用程序联系 ,与类似的功能。
import java.io.File; /** Super-fast file / directory(recursive) touch.进口java.io.file ; / **超高速文件/目录(递归)接触。 * It doesn't ask for confirmation. *它并不要求对方确认。 * Arguments: File / Directories to touch to current time. *论据:档案/目录触及到当前时间。 */ public class Touch { public static void main(String ... args) { long time = System.currentTimeMillis(); for(String fileName:args) touch(new File(fileName), time); } /** Recursively touch file and directories. * /市民阶层的接触, (公共静态无效的主要(字符串... args ) (长的时间= system.currenttimemillis ( ) ; (字符串文件名: args )触摸(新文件(文件名) ,时间) ; ) / **递归触摸文件和目录。 * @param File (file or directory) for touching. * @参数文件(文件或目录)感人。 */ public static void touch(File file, long time) { if(file.isDirectory()) for(File childFile:file.listFiles()) touch(childFile, time); file.setLastModified(time); } } * /公共静态无效触摸(档案文件,很长时间) (如果( file.isdirectory ( ) ) (档案childfile : file.listfiles ( ) )触摸( childfile ,时间) ; file.setlastmodified (时间) ; ) )
You can also download the你也可以下载 java executable class file Java的可执行类文件 . 。 You can run it as follows:您可以运行它如下:
java -classpath . Java的classpath下。 Touch *.html 触摸*.的HTML
Replace *.html with file name(s) and directories you want to update. *.取代HTML与档案名称( S )和目录,你要更新。 This requires JDK 1.5 or later.这就要求的JDK 1.5或更高版本。
Filed under提起下 Headline News头条新闻 , , How To如何 , , Java Software Java软件 , , Tech Note技术说明 | |
| |
RSS 2.0 2.0 | |
Trackback Trackback跟踪 this Article |此文章|
Email this Article电子邮件此文章
You may also like to read您也可以想读 |




































March 17th, 2007 at 7:13 am 2007年3月17日在上午07时13分
There’sa problem with the recursinion in the touch method.有问题,与recursinion在触摸的方法。
This line:这条路线:
if(file.isDirectory()) for(File childFile:file.listFiles()) touch(file, time);如果( file.isdirectory ( ) ) (档案childfile : file.listfiles ( ) )触摸(档案,时间) ;
should be:应该是:
if(file.isDirectory()) for(File childFile:file.listFiles()) touch(childFile, time);如果( file.isdirectory ( ) ) (档案childfile : file.listfiles ( ) )触摸( childfile ,时间) ;
July 5th, 2007 at 8:00 am 2007年7月5日在上午08点
Thanks.谢谢。 Corrected.纠正。
November 27th, 2007 at 1:29 pm 2007年11月27日在下午1时29分
Thanks for this little utility!感谢这个小实用工具!
It would be nice if you could also correct the class file..它会很好,如果您也可以正确的类文件..