io - Listing files in a directory matching a pattern in Java -


i'm looking way list of files match pattern (pref regex) in given directory.

i've found tutorial online uses apache's commons-io package following code:

collection getallfilesthatmatchfilenameextension(string directoryname, string extension) {   file directory = new file(directoryname);   return fileutils.listfiles(directory, new wildcardfilefilter(extension), null); } 

but returns base collection (according the docs it's collection of java.io.file). there way returns type safe generic collection?

see file#listfiles(filenamefilter).

file dir = new file("."); file [] files = dir.listfiles(new filenamefilter() {     @override     public boolean accept(file dir, string name) {         return name.endswith(".xml");     } });  (file xmlfile : files) {     system.out.println(xmlfile); } 

Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -