List files of a certain type



To list files of a certain type, create an instance of the FileFilter class and override its accept method. In the code example below we use an anonymous class to implement the accept method. When we use that instance when calling the list-method of the File class and it will filter out all the files with the ‘.txt’ file extension.

The above code does it the more traditional way, but we can shorten this code a bit by using lambda expressions:







Search for more Java info on this site here:
Custom Search


Please type any questions here.