1 import java.io.File;
2 import java.io.FileNotFoundException;
3 import java.io.PrintWriter;
4 import java.util.Scanner;
5
6 /**
7 This program applies line numbers to a file.
8 */
9 public class LineNumberer
10 {
11 public static void main(String[] args) throws FileNotFoundException
12 {
13 // Prompt for the input and output file names
14
15 Scanner console = new Scanner(System.in);
16 System.out.print("Input file: ");
17 String inputFileName = console.next();
18 System.out.print("Output file: ");
19 String outputFileName = console.next();
20
21 // Construct the Scanner and PrintWriter objects for reading and writing
22
23 File inputFile = new File(inputFileName);
24 Scanner in = new Scanner(inputFile);
25 PrintWriter out = new PrintWriter(outputFileName);
26 int lineNumber = 1;
27
28 // Read the input and write the output
29
30 while (in.hasNextLine())
31 {
32 String line = in.nextLine();
33 out.println("/* " + lineNumber + " */ " + line);
34 lineNumber++;
35 }
36
37 in.close();
38 out.close();
39 }
40 }