title: Java - How to remove blank lines from a text file
body: <p>I want to be able to remove blank lines from a text file, for example:</p>
  
  <pre><code>Average Monthly Disposable Salary
  1
  Switzerland 
  $6,301.73 
  2014
  
  2
  Luxembourg 
  $4,479.80 
  2014
  
  3
  Zambia 
  $4,330.98 
  2014
  </code></pre>
  
  <p>--To This:</p>
  
  <pre><code>Average Monthly Disposable Salary
  1
  Switzerland 
  $6,301.73 
  2014
  2
  Luxembourg 
  $4,479.80 
  2014
  3
  Zambia 
  $4,330.98 
  2014
  </code></pre>
  
  <p>All of the code I have is below:</p>
  
  <pre><code>public class Driver {
  
      public static void main(String[] args) 
      throws Exception {
  
          Scanner file = new Scanner(new File("src/data.txt"));
  
          PrintWriter write = new PrintWriter("src/data.txt");
  
          while(file.hasNext()) {
              if (file.next().equals("")) {
                  continue;
              } else {
                  write.write(file.next());
              }
          }
          print.close();
          file.close();
  
      }
  
  }
  </code></pre>
  
  <p>The problem is that the text file is empty once I go back and look at the file again.</p>
  
  <p>Im not sure why this is acting this way since they all seem to be blank characters, \n showing line breaks</p>