/** returns number of lines in file */ public static int numAllFileLines(File f, String ext) throws IOException { if (f.isFile()) return (f.getName().endsWith(ext) ? numFileLines(f) : 0); int counter = 0; Announce.doing("Counting in", f); for (File f2 : f.listFiles()) { counter += numAllFileLines(f2, ext); } Announce.done(); return (counter); }
/** Constructs FileLines from a file, shows progress bar (main constructor 2) */ public FileLines(File f, String announceMsg) throws IOException { if (announceMsg != null) { Announce.progressStart(announceMsg, f.length()); announceChars = 0; } br = new BufferedReader(new FileReader(f)); }
/** Closes the reader */ public void close() { try { br.close(); } catch (IOException e) { } if (announceChars != -1) Announce.progressDone(); announceChars = -1; }
/** * Returns next line. In case of an IOException, the exception is wrapped in a RuntimeException */ public String internalNext() { String next; try { next = br.readLine(); if (announceChars != -1 && next != null) Announce.progressAt(announceChars += next.length()); } catch (IOException e) { throw new RuntimeException(e); } return (next); }