Java HTML / XML How to - Convert XML string to XML file








Question

We would like to know how to convert XML string to XML file.

Answer

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
/*  ww w .  j av a  2 s .co  m*/
public class Main {
  public static void main(String args[]) throws Exception {
    String s = "<xmltag atr=value>tag data</xmltag>";
    FileWriter fr = new FileWriter(new File("a.txt"));
    Writer br = new BufferedWriter(fr);
    br.write(s);
    br.close();
  }
}