标签:lin div file nta har buffered port read over
public class TextFile implements Iterable<String>{ private BufferedReader br; public TextFile(String fileName) throws FileNotFoundException { br = new BufferedReader(new FileReader(fileName)); } @Override public Iterator<String> iterator() { return new Iterator<String>() { @Override public boolean hasNext() { try { br.mark(1); if (br.read() < 0) { return false; } br.reset(); return true; } catch (IOException e) { return false; } } @Override public String next() { try { return br.readLine(); } catch (IOException e) { return null; } } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }
An implementation of this using bufferedReader:
标签:lin div file nta har buffered port read over
原文地址:http://www.cnblogs.com/apanda009/p/7944631.html