Deep learning of file classes (ultra-simple Files manager)--"Thinking in Java" essay 028

Source: Internet
Author: User

1 //: Makedirectories.java2  PackageC10;3 4 ImportJava.io.File;5 ImportJava.text.SimpleDateFormat;6 Importjava.util.Date;7 8 /**9 * @time: Afternoon 7:59:23Ten * @date: April 29, 2017 One * @auther: Skyfffire A *    @version: v0.1 - */ -  Public classmakedirectories { the     Private Final StaticString Usage -= "\n\n1." Usage:makedirectories path1...\n " -+ "\tcreates each path\n\n" -+ "2.usage:makedirectories-d path1...\n" ++ "\tdeletes each path\n\n" -+ "3.usage:makedirectories-r path1 path2...\n" ++ "\trenames from path1 to path2\n\n"; A      at     /** - * How to use -      */ -     Private Static voidusage () { - System.out.println (usage); -System.exit (1); in     } -      to     /** + * Show details of a path -      *  the      * @paramf The path that needs to be displayed *      */ $     Private Static voidFileData (File f) {Panax NotoginsengSystem.out.println ("\n\nabsolute path:" +F.getabsolutepath ()); -SYSTEM.OUT.PRINTLN ("Can read:" +F.canread ()); theSystem.out.println ("Can Write:" +f.canwrite ()); +System.out.println ("GetName:" +f.getname ()); ASystem.out.println ("GetParent:" +f.getparent ()); theSystem.out.println ("GetPath:" +F.getpath ()); +System.out.println ("Length:" +f.length ());  -System.out.println ("LastModified:" $+NewSimpleDateFormat ("Yy-mm-dd"). $FormatNewDate (f.lastmodified () )); -          -         if(F.isfile ()) { theSystem.out.println ("It ' s a file.")); -}Else if(F.isdirectory ()) {WuyiSystem.out.println ("It ' s a directory.")); the         } -          WuSystem.out.println ("\ n")); -     } About      $     /** - * Print all path in current directory -      */ -     Private Static voidPrintpath () { A System.out.println (); +          theFile point =NewFile ("."); -          $string[] Path =point.list (); the          the          for(String nowstring:path) { the System.out.println (nowstring); the         } -          in System.out.println (); the     } the      About      Public Static voidMain (string[] args) { the Printpath (); the          the         if(Args.length < 1) { + usage (); -         } the         Bayi         //Update path name command the         if(Args[0].equals ("-R")) { the             if(Args.length! = 3) { - usage (); -}Else { theFile old =NewFile (args[1]); theFile Rname =NewFile (args[2]); the                  the                 if(Old.exists () &&!rname.exists ()) { -                     //Update file name the Old.renameto (rname); the}Else { theSYSTEM.OUT.PRINTLN ("Rename error:"94+ old.getname () + "to" +rname.getname ()); the                 } the                  the                 //Printing Information98 fileData (old); About FileData (rname); -             }101}//Execute Delete command102         Else if(Args[0].equals ("-D")) {103              for(intCount = 1; Count < Args.length; count++) {104File f =NewFile (Args[count]); the                 106                 //determine if f exists107                 if(F.exists ()) {108System.out.println (f + "exists"));109                      theSYSTEM.OUT.PRINTLN ("Deleting ..." +f);111 F.delete (); the 113 FileData (f); the}Else { theSystem.out.println (f + "path is not found.")); the                 }117             }118}//Execute Create command119         Else { -              for(intCount = 0; Count < Args.length; count++) {121File f =NewFile (Args[count]);122                 123 f.mkdirs ();124                 //the difference between F.mkdir () and F.mkdirs () is that the                 //mkdir cannot create a folder in a directory that does not exist126                 127System.out.println ("created" +f); - 129 FileData (f); the             }131         } the         133 Printpath ();134     }135 }136 137 ///:~

Optimized some of the unreasonable parts of the original book. The runtime places the argument list after Java XXX.

Deep learning of file classes (ultra-simple Files manager)--"Thinking in Java" essay 028

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.