Java.io.File.listFiles (filenamefilter filter) returns the abstract path an array group, which represents the files and directories in the directory that are represented by this abstract pathname, which satisfies the specified filter.
Statement
The following is a declaration of the Java.io.File.listFiles (FilenameFilter filter) Method:
PublicFile[] listfiles(filenamefilter filter)
Parameters
return value
The method returns the abstract path of the An array group, which represents the file and directory in the directory where this abstract pathname is represented, which satisfies the specified filter.
Abnormal
Example
The following example shows the use of the Java.io.File.listFiles (FilenameFilter filter) method.
PackageCom.Yiibai;ImportJava.Io.File;ImportJava.Io.FilenameFilter;Public Class Filedemo { Public Static voidMain(String[]Args) { FileF= Null; File[]Paths; Try{ Create new fileF= New File("C:/test"); Create new filename Filter FilenameFilterFilenameFilter= New FilenameFilter() { @Override Public BooleanAccept(FileDir, StringName) { If(Name.LastIndexOf(‘.‘) >0) { Get last index for '. ' Char IntLastIndex=Name.LastIndexOf(‘.‘); Get extension StringStr=Name.Substring(LastIndex); Match path name extension If(Str.equals(". txt")) { Return True; } } Return False; } }; Returns pathnames for files and directoryPaths=F.Listfiles(FilenameFilter); For each pathname in pathname array For(FilePath:Paths) { //prints file and directory Paths system.out.println (path); }}catch (Exception e) {//If any error occurs e.printstacktrace ();}}}
Let's compile and run the above program, which will produce the following results:
C:estchild_test. TXT
Java gets the specified file under the specified path/java.io.file.listfiles (filenamefilter filter)