Java tutorial
import java.io.FileReader; import java.io.IOException; import java.io.LineNumberReader; public class LineNumberIOApp { public static void main(String args[]) throws IOException { FileReader inFile = new FileReader("LineNumberIOApp.java"); LineNumberReader inLines = new LineNumberReader(inFile); String inputLine; while ((inputLine = inLines.readLine()) != null) { System.out.println(inLines.getLineNumber() + ". " + inputLine); } } }