Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a File[] for all *.properties under a given directory?

Tags:

java

file

search

I have a directory, C:\myDir.

under this directory, there may be folders and various files

How can I "loop" through this directory and build up a File array of all files with a .properties extension?

I want to do some processing on these files, the reason for a File[] is to keep it dynamic (so additional properties files added in the future will be included)

I'm hoping to do something like this :

public static void main (String[] vargs)
{

   // find all .properties files
   //

   //loop through property file and process
   {
      doSomething(myFile[i]);
   }

}

public void doSomething(File myfile) {}
like image 232
Jimmy Avatar asked Nov 30 '22 05:11

Jimmy


1 Answers

Look at FilenameFilter.

final FilenameFilter filter = new FilenameFilter() {
      public boolean accept(final File directory, final String name) {
        return name.endsWith(".properties");
      }
};
like image 114
JRL Avatar answered Apr 27 '23 01:04

JRL