/** * A static convenience method that returns the first line of the * specified file as list of strings, using the specified regexp as * delimiter. * * @param filename the file to read from * @param delim a regexp on which to split lines into fields (default whitespace) */ public static List<String> firstRecord(String filename, String delim) throws FileNotFoundException { RecordIterator it = new RecordIterator(filename, delim); if (!it.hasNext()) return null; return it.next(); }
/** * Just for testing. Reads from the file named on the command line, or from * stdin, and echoes the records it reads to stdout. */ public static void main(String[] args) throws FileNotFoundException { RecordIterator it = null; if (args.length > 0) { it = new RecordIterator(args[0]); } else { it = new RecordIterator(System.in); log.info("[Reading from stdin...]"); } while (it != null && it.hasNext()) { List<String> record = it.next(); for (String field : record) { System.out.printf("[%-10s]", field); } System.out.println(); } }