I'm trying to write an xml document object into a file, in a
specified encoding not necessarily UTF-8. The code is something like
this:
---
Source source = new DOMSource(document);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(fileName), encoding));
Result result = new StreamResult(out);
// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance().newTransformer
();
xformer.transform(source, result);
---
However, after save the header of the xml is always '<?xml
version="1.0" encoding="UTF-8" ?>' . How do I make the header
contain the encoding it's saved in, for example, "SJIS"?