private static void visitFiles( final File file, final Processor<String> processor, final int prefix) { final String absolutePath = file.getAbsolutePath(); processor.process(prefix < absolutePath.length() ? absolutePath.substring(prefix) : ""); if (file.isDirectory()) { for (final String next : file.list()) { visitFiles(new File(file, next), processor, prefix); } } }
public static void readFile( final File file, final Charset charset, final Processor<CharSequence> lineProcessor) throws IOException { final LineNumberReader reader = new LineNumberReader( new InputStreamReader(new FileInputStream(file), charset), BUFFER_LENGTH); int lineCounter = 0; try { String line; while ((line = reader.readLine()) != null) { lineProcessor.process(line); lineCounter++; } } catch (Exception th) { throw new RuntimeException("line number = " + lineCounter, th); } finally { reader.close(); } }