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..它會很好,如果您也可以正確的類文件..