I am reusing the the code from @Tim Bender here:
First get a list of all the needed files as shown by @Tim Bender (shown here again for completeness). And no third party libraries are needed.
File theDirectory = new File("/home/example");
File[] children = theDirectory.listFiles(new FileFilter(){
public boolean accept(File file) {
if (file.isFile()) {
//Check other conditions
return true;
}
return false;
}
});
Now iterate over this array and use java.nio
API for file reading in a single go (without br.readLine()
)
public StringBuilder readReplaceFile(File f) throws Exception
{
FileInputStream fis = new FileInputStream(f);
FileChannel fc = fis.getChannel();
int sz = (int)fc.size();
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
CharBuffer cb = decoder.decode(bb);
StringBuilder outBuffer = new StringBuilder(cb);
fc.close();
return outBuffer;
}
Hope this help