public class LineReader extends Object implements Iterable<String>
try { BufferedReader br = new BufferedReader(new FileReader(file)); for (String line = null; (line = br.readLine()) != null; ) { // work } } catch (IOException ioe) { // handling code } finally { br.close(); }with the code
for (String line : new LineReader(file) { // work }This class with automatically close the stream up on finishing or upon error. All
IOException
instances are rethrown as IOError
.Constructor and Description |
---|
LineReader(File f)
Creates a line reader for the provided file.
|
Copyright © 2012. All Rights Reserved.