title: while loop is only printing one time instead of for the entire loop
body: <p>I have a program in which I use a while loop to print both to the console and to a html file. However even though it prints to the console the program will only print the final line to the html file.  Here is the code for my loop which is supposed to print the information extracted from a text file for the lines 9 to 16.</p>
  
  <pre><code>  //read the txt file
  Path objPath = Paths.get("dirsize.txt");  
  if (Files.exists(objPath))
  {
  
      File objFile = objPath.toFile();
    try(BufferedReader in = new BufferedReader(
                            new FileReader(objFile)))
     {
      String line = in.readLine();
      int lineNum = 1;
      //extract the month
      String monthSubstring = line.substring(25,27);
      month = Integer.parseInt(monthSubstring) -1 ;
      //extact the year
      String yearSubstring = line.substring(31,35);
      year = (Integer.parseInt(yearSubstring));
      //extract the date
      String daySubstring = line.substring(28,30);
      day = Integer.parseInt(daySubstring);
       PrintWriter out = new PrintWriter (new BufferedWriter(new FileWriter("Output.html")));
      while(line != null)
      {
        line = in.readLine();
        lineNum ++;
        if (lineNum == 3)
         {
             //extract the hour
              String hourSubstring = line.substring(21,23);
               hour = Integer.parseInt(hourSubstring); 
              //extract the minute
              String minuteSubstring = line.substring(24,26);
               minute = Integer.parseInt(minuteSubstring);
              //extract the second
              String secondSubstring = line.substring(27,29);
              second= Integer.parseInt(secondSubstring);
             }
        if(lineNum ==5)
         {
              //Extract the branch
              strBranch = line.substring(22, 27);        
         }        
        if (lineNum == 6)
        {
               //Extract the computer
               strCPU = line.substring(26,32);
        }   
       if (lineNum &gt;= 9 &amp;&amp; lineNum &lt;= 16)
        {
            //call the MyDirectory methods to get the files name,size and number of files
            MyDirectory directory = new MyDirectory(line);
            fileName = directory.getName();
            fileSize = directory.getsize();
            fileNum = directory.getNum();
            //create the dteDate calender
            GregorianCalendar dteDate = new GregorianCalendar(year, month, day, hour, minute, second);
            //fromat the date
            SimpleDateFormat strDate = new SimpleDateFormat("MMM dd, yyyy h:m");
          //Write the data to the file
           out.println((strBranch + "; " +
                    strCPU + "; "  + 
                    strDate.format(dteDate.getTime())) + "; " +
                    fileName + "; " +
                    fileSize + "; " + 
                    fileNum);
           //create the necessary output for the console
            System.out.println((strBranch + "; " +
                    strCPU + "; "  + 
                    strDate.format(dteDate.getTime())) + "; " +
                    fileName + "; " +
                    fileSize + "; " + 
                    fileNum);
          }    
         out.flush();
      }
  
     }   
  
    //catch any IOExceptions and print out e
   catch (IOException e)
    {
      System.out.println(e);  
    }
  
  }
  </code></pre>
  
  <p>EDIT: Through advice posted in answers I now have my output for everything but im having a hard time formatting it the html file has all the lines together with no spacing I tried using "\n" at the end of my output but then my code doesn't compile because it says a null is not allowed there anyone know how to format this into lines when it wont let me put "\n" at the end of my print method?</p>
  
  <p>I'm unsure if this is to much code or not enough to solve the problem and if I should add anything to my post or take anything out just let me know.</p>