0
我需要將文件從ISO-8859-2字符集轉換爲UTF-8。Java - 將xml文件從ISO-8859-2轉換爲UTF-8
我的代碼是:
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
DOMSource domSource = new DOMSource(doc);
String fileName2 = UUID.randomUUID().toString() + "222";
Writer out = new OutputStreamWriter(new FileOutputStream("/Users/user/Kohana/" + fileName2 + ".xml"), "UTF8");
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(domSource, new StreamResult(out));
但問題是,改造後,該文件仍然是ISO-8859-2。
我在做什麼錯了?
被它是'UTF8'還是'UTF-8'? –
我希望它會是UTF-8。但在你問題後,我檢查了UTF8,我的文件仍然是ISO -... – Ilkar
原始XML是否將其編碼聲明爲ISO-8859-2? – erickson