title: Read file, replace string and create a new one with all content
body: <p>I am trying to replace <code>?</code> with <code>-</code> in my text document but just the <code>ArrayList&lt;String&gt;</code> is being written in the new file without all lines of the old one. How can I fix that?</p>
  
  <pre><code>File file = new File("D:\\hl_sv\\L09MF.txt");
  
  ArrayList&lt;String&gt; lns = new ArrayList&lt;String&gt;();
  Scanner scanner;
  try {
  
      scanner = new Scanner(file);
  
      int lineNum = 0;
      while (scanner.hasNextLine()) {
          String line = scanner.nextLine();
          lineNum++;
          if (line.contains("?")) {
              line = line.replace("?", "-");
              lns.add(line);
  
              // System.out.println("I found it on line " + lineNum);
          }
      }
      lines.clear();
      lines = lns;
      System.out.println("Test: " + lines);
  
      FileWriter writer;
      try {
          writer = new FileWriter("D:\\hl_sv\\L09MF2.txt");
          for (String str : lines) {
              writer.write(str);
          }
  
          writer.close();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  </code></pre>