Create LineNumberReader from FileReader
import java.io.FileReader; import java.io.LineNumberReader; class LineViewer { public static void main(String[] args) throws Exception { LineNumberReader lnr = null; FileReader fr = new FileReader(args[0]); lnr = new LineNumberReader(fr); String s; while ((s = lnr.readLine()) != null) System.out.println(lnr.getLineNumber() + ": " + s); } }