?
Solved

Get all files that end in a specific file extension.

Posted on 2006-06-02
3
Medium Priority
?
185 Views
Last Modified: 2010-03-31
Hey,

How can I get names for all files into a list or an array that end with, for example, .txt from one directory?

Thanks,
Kate
0
Comment
Question by:kasiencja
  • 3
3 Comments
 
LVL 14

Accepted Solution

by:
StillUnAware earned 1200 total points
ID: 16818670
String[] fileNames = (new File("path")).list(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        if(name.endsWith(".ext"))
            return true;
        return false;
    });
0
 
LVL 14

Expert Comment

by:StillUnAware
ID: 16818689
A small correction:

import java.io.*;

    String[] fileNames = (new File("C:")).list(new FilenameFilter() {
      public boolean accept(File dir, String name) {
        if(name.endsWith(".sys"))
          return true;
        return false;
      }
    });
    for(String s : fileNames)
      System.out.println(s);
0
 
LVL 14

Expert Comment

by:StillUnAware
ID: 16818693
glad to help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question