Is there a built in Java code that will parse a given folder and search it for .txt
files?
You can use the listFiles()
method provided by the java.io.File
class.
import java.io.File; import java.io.FilenameFilter; public class Filter { public File[] finder( String dirName){ File dir = new File(dirName); return dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String filename) { return filename.endsWith(".txt"); } } ); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With