title: How to edit line on file
body: <p>This is my code:</p>
  
  <pre><code>public class FileReplace {
      List&lt;String&gt; lines = new ArrayList&lt;String&gt;();
      String line = null;
  
      public void  doIt() {
          try {
              File f1 = new File("d:/new folder/t1.htm");
              FileReader fr = new FileReader(f1);
              BufferedReader br = new BufferedReader(fr);
              while ((line = br.readLine()) != null) {
                  if (line.contains("java"))
                      line = line.replace("java", " ");
                  lines.add(line);
              }
              fr.close();
              br.close();
  
              FileWriter fw = new FileWriter(f1);
              BufferedWriter out = new BufferedWriter(fw);
              for(String s : lines)
                   out.write(s);
              out.flush();
              out.close();
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
  
      public static void main(String args[]) {
          FileReplace fr = new FileReplace();
          fr.doIt();
      }
  }
  </code></pre>
  
  <p>and I have this text:</p>
  
  <p>javascript_js<br/>
  java_swing<br/>
  java_fx<br/>
  kotlin<br/>
  python<br/></p>
  
  <p>I wanna edit <code>java_fx</code> to <code>java</code>. My code is deleting all content and write <code>java_fx</code>, how do I edit <code>java_fx</code> without erasing all content in file?</p>