Java finds the specified (prefix, suffix, or intermediate included) file

Source: Internet
Author: User

1 ImportJava.io.File;2 Importjava.io.FileNotFoundException;3 4  Public classSearchfile {5 6      Public Static voidMain (string[] args)throwsFileNotFoundException {7File files =NewFile ("f:/");//Create a file object, point toF Packing Catalogue8string[] names = Files.list ();//get the F-packing directory for all files and paths, and return as an array of strings9          for(String s:names) {//iterating through a string arrayTen             BooleanA = S.startswith ("ja");//file name prefix with ja returns TRUE, none returns False One             BooleanB = (NewFile (Files.getabsolutepath () +s)). Isfile ();//returns True if the contents of the string that this loop is pointing to are files. Otherwise, false is returned A             Booleanc = s.contains ("va");//whether the file name contains "VA", contains the return true, otherwise false -             if(A&&B) {//the conditions here are modified as needed -System.out.println (s);//print out files that match your criteria the             } -         } -     } -  +}

Line 11th: A detail question

If the

Boolean B = (new File (Files.getabsolutepath () +s)). Isfile ();

Switch

Boolean B = (new File (s)). Isfile ();

Will always return false, because no path is specified, the system will find the file name pointed to by S in the directory of the project, but there is no such file in the project directory, so it will always be judged that the file does not exist

Java finds the specified (prefix, suffix, or intermediate included) file

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.