title: Replace String in file using marker in Java
body: <p>i have problem when try to replacing String in File.
  in my file i have :</p>
  
  <pre><code>&lt;!-- Header --&gt;
  &lt;header fontName="Arial" size="24"/&gt;
  &lt;!-- Content --&gt;
  &lt;content&gt;
      &lt;fontName="Arial" size="11"/&gt;
  &lt;/content&gt;
  </code></pre>
  
  <p>How to replace fontName and size just for <code>&lt;!-- Header --&gt;</code> ?
  <br/>
  This is my code for replace </p>
  
  <pre><code>public class StringReplacement {
       public static void main(String args[])
           {
           try
               {
               File file = new File("file.xml");
               BufferedReader reader = new BufferedReader(new FileReader(file));
               String line = "", oldtext = "";
               while((line = reader.readLine()) != null)
                   {
                   oldtext += line + "\r\n";
               }
               reader.close();
               // replace a word in a file
               //String newtext = oldtext.replaceAll("drink", "Love");
  
               //To replace a line in a file
               String newtext = oldtext.replaceAll("Arial", "Times New Roman");
  
               FileWriter writer = new FileWriter("file.xml");
               writer.write(newtext);
               writer.close();
           }
           catch (IOException ioe)
               {
               ioe.printStackTrace();
           }
       }
  }
  </code></pre>
  
  <p>But it just replace all the text to be replaced.</p>