title: Find String in text file, delete line and ones below
body: <p>I have a bit of code to find a string in a text file, print the line the string is on and then print the 5 lines below it. However, I need to modify it so that instead of printing, it deletes/removes the line after the string is found. How would I go about doing this?</p>
  
  <pre><code>File file = new File("./output.txt");
  Scanner in = null;
  try {
      in = new Scanner(file);
      while (in.hasNext()) {
          String line = in.nextLine();
          if (line.contains("(1)")) {
              for (int a = 0; in.hasNextLine() &amp;&amp; a &lt; 6; a++) {
                  System.out.println(line);
                  line = in.nextLine();
              }
          }
      }
  } catch (Exception e) {
  }
  </code></pre>