title: File output deletes all the content
body: <p>I am trying to make a program which removes text from a file. The text to remove and the file path are provided as command line arguments. Everything goes fine, but when I open the file after the program has finished running, it's all empty. What am I doing wrong?</p>
  
  <pre><code>import java.io.File;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Scanner;
  
  public class Remove {
  public static void main(String[] args) throws IOException{
      if(args.length != 2) {
          System.out.println("usage : java Remove stringToRemove filePath");
          System.exit(1);
      }
      String stringToReplace = args[0];
      String path = args[1];
      File file = new File(path);
      if(!file.exists()) {
          System.out.println("No such file exists!");
          System.exit(2);
      }
  
      Scanner input = new Scanner(file);
      PrintWriter output = new PrintWriter(file);
  
      while(input.hasNext()) {
          String currentLine = input.nextLine();
          currentLine = currentLine.replaceAll(stringToReplace, "");
          output.println(currentLine);
      }
  
      input.close();
      output.close();
  
      System.out.println("Operation Successful");
  }
  }
  </code></pre>