title: How to remove blank lines from a text file in java
body: <p>I am trying to duplicate the original into a new file. In the new file I want the exact same things as the original BUT no blank lines.</p>
  
  <p>Note: I looked at other posts and tried with no success.</p>
  
  <p><strong>Currently:</strong></p>
  
  <pre><code>1  
  
  2  
  
  3  
  </code></pre>
  
  <p><strong>How I want it to be: -- no blank lines</strong></p>
  
  <pre><code>1  
  2  
  3
  </code></pre>
  
  <p>Here is my code so far:</p>
  
  <pre><code>   inputFileName = "x.txt";
     outputFileName = "y.txt";
  
     inputFile = new BufferedReader(new FileReader(inputFileName));
     outputFile = new PrintWriter(new FileWriter(outputFileName));
  
     String lineOfText = inputFile.readLine();
  
     while(lineOfText != null)
     {
         if (lineOfText.isEmpty())
         {
          outputFile.print("null");
         }
  
         outputFile.println(lineOfText);
         lineOfText = inputFile.readLine();
     } 
  
     inputFile.close();
     outputFile.close();
  }
  </code></pre>
  
  <p>Thank you for all who can possibly help. I assumed that <code>print("null")</code> would print out 'nothing' but it indeed prints out null, I do not know how to print out 'nothing'.</p>