import java.io.*; import java.util.Scanner; /** Add line numbers to a file @author P. Conrad based on code from link below @see ReadWithScanner @see http://www.javapractices.com/topic/TopicAction.do?Id=42 */ public class AddLineNumbers extends ReadWithScanner { private int lineNumber = 0; /** @param args first arg is filename; rest unused */ public static void main(String [] args) throws FileNotFoundException { AddLineNumbers aln = new AddLineNumbers(args[0]); aln.processLineByLine(); } /** Constructor. @param aFileName full name of an existing, readable file. */ public AddLineNumbers(String aFileName){ super(aFileName); } /** print the line on System.out with a line number in front */ protected void processLine(String aLine){ this.lineNumber ++; System.out.println(lineNumber + aLine); } }