title: Adding numbers in the beginning of each line in a file
body: <p>I have a file with some random code (can use any other random file) I want to add the number of lines at the start of each line. 
  For example:</p>
  
  <pre><code>1.
  2.
  3.
  </code></pre>
  
  <p>etc.
  Also removing any blank lines and keep numbering the lines correctly. 
  here's my code so far:</p>
  
  <pre><code>public static void main(String[] args) throws FileNotFoundException 
  {
      boolean foundException = false;
      Scanner keyboard = new Scanner(System.in);
      do {
          try {
              System.out.print("Please enter input file name: ");
              String fileName = keyboard.next();
              File inputFile = new File("inputfile.txt"); 
              Scanner scanner = new Scanner(new File("inputfile.txt"));
              PrintStream out = new PrintStream(new File("inputfile.txt"));
  
              while(scanner.hasNextLine()){
                  String line = scanner.nextLine();
                  line = line.trim();
                  if(line.length() &gt; 0)
                      out.println(line);
              }
  
              for( int i = 1; i &lt; inputFile.length(); i++){
                  System.out.println( i + "." + inputFile);
              }
              foundException = false;
          }
          catch (FileNotFoundException x) {
              System.out.println("File does not exist");
              foundException = true;
          }
  
      } while (foundException);
  }
  }
  </code></pre>
  
  <p>but the result I get is very large number of lines + the file name like " 300. inputfile.txt "
  the whole file has about 25 lines but I'm getting 500+ lines, I'm assuming it's counting every word after a space?
  I have another question about the file, I'm not sure if im calling the file correctly in the code which is "inputfile.txt" the file location is inside the folder of the project.
  thanks for your time.</p>