title: How can I display file with line numbers in my Java program?
body: <p>I want my program to display the contents of the file the user inputs with each line preceded with a line number followed by a colon. The line numbering should start at 1.</p>
  
  <p>This is my program so far:</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class USERTEST {
     public static void main(String[] args) throws IOException
     {
     Scanner keyboard = new Scanner(System.in);
     System.out.print("Enter a file name: ");
     String filename = keyboard.nextLine();
  
     File file = new File(filename);
     Scanner inputFile = new Scanner(file);
     String line = inputFile.nextLine();
  
     while (inputFile.hasNext()){
     String name = inputFile.nextLine();
  
     System.out.println(name);
     }
  
     inputFile.close();
  
     }
  
  }
  </code></pre>
  
  <p>I can display the contents of the file so far, but I don't know how to display the contents with the line numbers.</p>