Java IO file suffix filtering summary, javaio suffix Filtering
Effect: list specific suffix files under a directory (for example, txt files under the root directory of the D Drive)
Import java. io. file; import java. io. filenameFilter; public class QueryFile implements FilenameFilter {String extension; // file extension public QueryFile (String extension) {this. extension = ". "+ extension. toLowerCase (); // File extension standardization} @ Overridepublic boolean accept (File dir, String name) {// rewrite the FilenameFilter interface method file File = new File (dir, name ); if (file. getName (). toLowerCase (). endsWith (extension) {return true;} return false;} public static void main (String [] args) {File file = new File ("D :/"); queryFile query = new QueryFile ("txt"); // String [] array = file with the suffix txt. list (query); // start to filter for (int I = 0; I <array. length; I ++) {System. out. println (array [I]) ;}}
Note:
The FilenameFilter interface is used to filter files. The same interface is FileFilter.
The above is all the content about the summary of the I/O file suffix filtering. If you still do not understand it, refer to the following articles or directly discuss it in the following message area, thank you for your support.