title: removing extra white spaces from text files
body: <p>I have number of text files in the following format:</p>
  
  <pre><code>196903274115371008    @266093898 
  
  Prince George takes his first public steps with his mom,                              Catherine, Duchess of    
  
  Cambridge.
  </code></pre>
  
  <p>I would like to remove all extra while spaces + new line characters except the first new line characters. So I would like to above to be like this: </p>
  
  <pre><code>196903274115371008@266093898 
  
  Prince George takes his first public steps with his mom, Catherine, Duchess of Cambridge.
  </code></pre>
  
  <p>I wrote the following code :</p>
  
  <pre><code>package remove_white_space222;
  
  import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.io.IOException;
  
  
  public class Remove_white_space222 {
  
      public static void main(String[] args) throws FileNotFoundException, IOException {
  
          FileReader fr = new FileReader("input.txt"); 
          BufferedReader br = new BufferedReader(fr); 
          FileWriter fw = new FileWriter("outfile.txt"); 
          String line;
  
          while((line = br.readLine()) != null)
          { 
              line = line.trim(); // remove leading and trailing whitespace
              line=line.replaceAll("\\s+", " ");
              fw.write(line);
  
  
          }
          fr.close();
          fw.close();
      }
  
  }
  </code></pre>
  
  <p>Thanks in advance for your help,,,,</p>