设置行号代码
import java.io.*; class DemoBuffer { public static void main(String[] args)throws Exception { FileReader file=new FileReader("abc.txt"); LineNumberReader lnr=new LineNumberReader(file); String line=null; while((line=lnr.readLine())!=null) { System.out.println(lnr.getLineNumber()+","+line); } } }