Some methods of the Java 19-13 file Class 2

Source: Internet
Author: User

1  PackageZl_file;2 3 ImportJava.io.File;4 Importjava.io.IOException;5 ImportJava.text.SimpleDateFormat;6 Importjava.util.Date;7 8 /*9       Judging function :Ten Public Boolean isdirectory (): Determines whether it is a directory (folder) One Public Boolean isfile (): Determines whether the file is A Public Boolean exists (): Determine if there is - Public Boolean CanRead (): Determines whether it is readable - Public Boolean canWrite (): Determines if writable the Public Boolean Ishidden (): Determines whether to hide -       Get features : - Public String GetAbsolutePath (): Gets the absolute path - Public String GetPath (): Get relative path + Public String GetName (): Get name - Public long Length (): Gets the length. Number of bytes + Public Long LastModified (): Gets the last modification time, in milliseconds this can be seen if someone has moved their files. A       Get features : at Public string[] list (): Gets an array of names for all files or folders under the specified directory - Public file[] Listfiles (): Gets the file array of all files or folders under the specified directory -  */ -  Public classFileDemo2 { -  -      Public Static voidMain (string[] args)throwsIOException { in         //Create a folder first -File file1 =NewFile ("H:\\demo\\test"); to file1.mkdirs (); +         //create a file on the path above -File file2 =NewFile ("H:\\demo\\test\\a.txt"); the file2.createnewfile (); *          $         //Public Boolean isdirectory (): Determines whether it is a directory (folder)Panax NotoginsengFile File3 =NewFile ("H:\\demo\\test\\a.txt"); -System.out.println (File3.isdirectory ());//false, the          +File file4 =NewFile ("H:\\demo\\test"); ASystem.out.println (File4.isdirectory ());//true the          +         //Public Boolean isfile (): Determines whether the file is -File file5 =NewFile ("H:\\demo\\test\\a.txt"); $System.out.println (File5.isfile ());//true $          -         //Public Boolean exists (): Determine if there is -File File6 =NewFile ("H:\\demo\\test\\a.txt"); theSystem.out.println (File6.isfile ());//true -File File7 =NewFile ("H:\\demo\\test\\b.txt");WuyiSystem.out.println (File7.isfile ());//false the          -         //Public Boolean CanRead (): Determines whether it is readable Wu         //Public Boolean canWrite (): Determines if writable -         //Public Boolean Ishidden (): Determines whether to hide AboutSystem.out.println (File6.canread ());//true $System.out.println (File6.canwrite ());//true -System.out.println (File6.ishidden ());//flase -          -         //Get features A         //Public String GetAbsolutePath (): Gets the absolute path +System.out.println (File6.getabsolutepath ());//H:\demo\test\a.txt the          -         //Public String GetPath (): Get relative path $System.out.println (File6.getpath ());//H:\demo\test\a.txt, in the program folder, there will be no drive letter the          the         //Public String GetName (): Get name theSystem.out.println (File6.getname ());//a.txt the          -         //Public long Length (): Gets the length. Number of bytes inSystem.out.println (File6.length ());//0, there's nothing inside. the          the         //Public Long LastModified (): Gets the last modified time, millisecond value AboutSystem.out.println (File6.lastmodified ());//1474975514541 the          the         //1474975514541 theDate d =NewDate (1474975514541L); +SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); -String s =Sdf.format (d); theSystem.out.println (s);//2016-09-27 19:25:14Bayi          the         //Advanced Access Features the         //Public string[] list (): Gets an array of names for all files or folders under the specified directory -File File =NewFile ("h:\\"); -string[] str = file.list ();//here is an array of all the folders under the H disk and the names of the files the         //need to traverse the          for(String s1:str) { theSystem.out.println (S1);//will get all the folders under the H disk and the name of the file the         } -          the         //Public file[] Listfiles (): Gets the file array of all files or folders under the specified directory theFile[] f = file.listfiles ();//The effect is similar to the above, except that the array type is file type the         //Traverse94          for(File fi:f) { theSystem.out.println (Fi.getname () +fi.length ()); the             //because it is of type file, you can call the file's method to see the properties of the files in it the         }        98     } About}

Some methods of the Java 19-13 file Class 2

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.