package com.cug.linenumber;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
public class LineNumberReaderDemo {
<span style="white-space:pre"> </span>public static void main(String[] args) throws IOException {
<span style="white-space:pre"> </span>LineNumberReader lnr = new LineNumberReader(new FileReader("a.txt"));
<span style="white-space:pre"> </span>String line = null;
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>while((line = lnr.readLine()) != null){
<span style="white-space:pre"> </span>System.out.println(lnr.getLineNumber()+":"+line);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>lnr.close();
<span style="white-space:pre"> </span>}
}
Java基础----LineNumberReader
最新推荐文章于 2021-05-31 18:18:38 发布