title: how to convert xml file to a string and write it to another file in xml format?
body: <p>i have a requirement in that i need to convert the xml file in to a string and then write it to another file as valid xml format.</p>
  
  <p>i tried few logics but all of those are failed to write string to xml file format as it is always taking as XML tags but not as a string.</p>
  
  <p>for example my code was </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Students&gt;
      &lt;Student_Name&gt;Srinivas&lt;/Student_Name&gt;
      &lt;Student_FullName&gt;Srinivas_Kumar&lt;/Student_FullName&gt;
      &lt;DOB&gt;1992-09-25&lt;/DOB&gt;
      &lt;FlatNo&gt;#04, 8th main&lt;/FlatNo&gt;
      &lt;Locality&gt;Gandhi Road&lt;/Locality&gt;
  &lt;/Students&gt;
  </code></pre>
  
  <p>expected output should be like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ns0:message&gt;
  &lt;Students&gt;&lt;Student_Name&gt;Srinivas&lt;/Student_Name&gt;&lt;Student_FullName&gt;Srinivas_Kumar&lt;/Student_FullName&gt;&lt;DOB&gt;1992-09-25&lt;/DOB&gt;&lt;FlatNo&gt;#04, 8th main&lt;/FlatNo&gt;&lt;Locality&gt;Gandhi Road&lt;/Locality&gt;&lt;/Students&gt;
  &lt;/ns0:message&gt;
  </code></pre>
  
  <p>please help me in this.</p>
  
  <p>one of my logic is </p>
  
  <pre><code>public static void main(String[] args)throws IOException { 
      FileInputStream fin = new FileInputStream("path"); 
      FileOutputStream fout = new FileOutputStream("path"); 
      BufferedReader br = new BufferedReader(new InputStreamReader(fin)); 
      BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fout)); 
      String initialtag = . 
      String endtag = . 
      String line ; 
      bw.write(initialtag); 
      while((line = br.readLine()) != null) { 
          line.replaceAll("&lt;","&amp;lt"); 
          line.replaceAll("&gt;","&amp;gt"); 
          bw.write(line); 
      } 
          bw.write(endtag); 
          bw.close(); 
  }
  </code></pre>