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