Java IO file suffix filtering summary, javaio suffix Filtering

Source: Internet
Author: User

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.

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.