编译: javac triproot.java
运行:java triproot -init [Dir you want init] [Output file name]
java triproot -check [Dir you want check] [Trip file,that must be init early]
在windows2k、window2003、AS5.1上测试过,linux下编译运行要改个字符,注释里有。
[table=95%][tr][td][font=FixedSys][color=#000000] [color=#0000FF]import[/color] [color=#FF0000]java[/color][color=#0000CC].[/color][color=#FF0000]io[/color][color=#0000CC].[/color][color=#0000CC]*[/color][color=#0000CC];[/color]
[color=#0000FF]import[/color] [color=#FF0000]java[/color][color=#0000CC].[/color][color=#FF0000]util[/color][color=#0000CC].[/color][color=#0000CC]*[/color][color=#0000CC];[/color]
[color=#0000FF]import[/color] [color=#FF0000]java[/color][color=#0000CC].[/color][color=#FF0000]lang[/color][color=#0000CC].[/color][color=#0000CC]*[/color][color=#0000CC];[/color]
[color=#0000FF]import[/color] [color=#FF0000]java[/color][color=#0000CC].[/color][color=#FF0000]text[/color][color=#0000CC].[/color][color=#0000CC]*[/color][color=#0000CC];[/color]
[color=#0000FF]public[/color] [color=#0000FF]class[/color] triproot
[color=#0000CC]{[/color]
[color=#0000FF]static[/color] [color=#FF0000]ArrayList[/color] dirlist [color=#0000CC]=[/color] [color=#0000FF]new[/color] [color=#FF0000]ArrayList[/color][color=#0000CC]([/color][color=#0000CC])[/color][color=#0000CC];[/color]
[color=#0000FF]static[/color] [color=#FF0000]HashSet[/color] [color=#FF0000]filewriter[/color][color=#0000CC]=[/color][color=#0000FF]new[/color] [color=#FF0000]HashSet[/color][color=#0000CC]([/color][color=#0000CC])[/color][color=#0000CC];[/color]
[color=#0000FF]static[/color] [color=#0000FF]long[/color] filenum[color=#0000CC]=[/color]0[color=#0000CC];[/color]
[color=#0000FF]static[/color] [color=#0000FF]long[/color] dirnum[color=#0000CC]=[/color]0[color=#0000CC];[/color]
[color=#0000FF]public[/color] [color=#FF0000]String[/color] getDateString[color=#0000CC]([/color][color=#0000FF]long[/color] unixtime[color=#0000CC])[/color] [color=#FF9900]//convert unix time to human time
[/color]
[color=#0000CC]{[/color]
[color=#FF0000]Date[/color] [color=#FF0000]date[/color] [color=#0000CC]=[/color] [color=#0000FF]new[/color] [color=#FF0000]Date[/color][color=#0000CC]([/color]unixtime[color=#0000CC])[/color][color=#0000CC];[/color]
[color=#FF0000]SimpleDateFormat[/color] [color=#FF0000]formatter[/color] [color=#0000CC]=[/color] [color=#0000FF]new[/color] [color=#FF0000]SimpleDateFormat[/color][color=#0000CC]([/color][color=#FF00FF]"yyyy-MM-dd HH:mm:ss"[/color][color=#0000CC])[/color][color=#0000CC];[/color]
[color=#FF0000]String[/color] dateString [color=#0000CC]=[/color] [color=#FF0000]formatter[/color][color=#0000CC].[/color][color=#FF0000]format[/color][color=#0000CC]([/color][color=#FF0000]date[/color][color=#0000CC])[/color][color=#0000CC];[/color]
[color=#0000FF]return[/color] dateString[color=#0000CC];[/color]
[color=#0000CC]}[/color]
[color=#0000FF]void[/color] detectwhatisit[color=#0000CC]([/color][color=#FF0000]String[/color] receivefilename[color=#0000CC])[/color] [color=#FF9900]//detect receivefilename is a dir or a file,push dir to dirlist,push file to filewriter;
[/color]
[color=#0000CC]{[/color]
[color=#FF0000]File[/color] dir2 [color=#0000CC]=[/color] [color=#0000FF]new[/color] [color=#FF0000]File[/color][color=#0000CC]([/color]receivefilename[color=#0000CC])[/color][color=#0000CC];[/color]
[color=#0000FF]boolean[/color] isDir [color=#0000CC]=[/color] dir2[color=#0000CC].[/color][color=#FF0000]isDirectory[/color][color=#0000CC]([/color][color=#0000CC])[/color][color=#0000CC];[/color]
[color=#0000FF]if[/color] [color=#0000CC]([/color]isDir[color=#0000CC])[/color]
[color=#0000CC]{[/color]
triproot[color=#0000CC].[/color]dirnum[color=#0000CC]+[/color][color=#0000CC]+[/color][color=#0000CC];[/color]
triproot[color=#0000CC].[/color]dirlist[color=#0000CC].[/color][color=#FF0000]add[/color][color=#0000CC]([/color]receivefilename[color=#0000CC])[/color][color=#0000CC];[/color]
[color=#0000CC]}[/color]
[color=#0000FF]else[/color]
[color=#0000CC]{[/color]
triproot[color=#0000CC].[/color]filenum[color=#0000CC]+[/color][color=#0000CC]+[/color][color=#0000CC];[/color]
[color=#FF0000]String[/color] [color=#FF0000]lastmodified[/color][color=#0000CC]=[/color]getDateString[color=#0000CC]([/color]dir2[color=#0000CC].[/color][color=#FF0000]lastModified[/color][color=#0000CC]([/color][color=#0000CC])[/color][color=#0000CC])[/color][color=#0000CC];[/color]
triproot[color=#0000CC].[/color][color=#FF0000]filewriter[/color][color=#0000CC].[/color][color=#FF0000]add[/color][color=#0000CC]([/color][color=#FF00FF]"Size : "[/color][color=#0000CC]+[/color]dir2[color=#0000CC].[/color][color=#FF0000]length[/color][color=#0000CC]([/color][color=#0000CC])[/color] [color=#0000CC]+[/color][color=#FF00FF]"\t Last modify : "[/color][color=#0000CC]+[/color][color=#FF0000]lastmodified[/color] [color=#0000CC]+[/color] [color=#FF00FF]" \t File name :"[/color][color=#0000CC]+[/color]dir2[color=#0000CC].[/color][color=#FF0000]getPath[/color][color=#0000CC]([/color][color=#0000CC])[/color] [color=#0000CC])[/color][color=#0000CC];[/color]
[color=#0000CC]}[/color][color=#FF9900]//else end
[/color]
[color=#0000CC]}[/color][color=#FF9900]//end of detectwhatisit
[/color]
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/