Java tutorial
import java.io.FileReader; import java.io.LineNumberReader; public class Main { public static void main(String[] args) throws Exception { LineNumberReader r = new LineNumberReader(new FileReader("yourFile.txt")); String line = null; while ((line = r.readLine()) != null) { System.out.println(r.getLineNumber() + ": " + line); } r.close(); } }