我实现下面的代码我的Java应用程序中现在Java的XML编码错误
//create string from xml tree
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
String xmlString = sw.toString().replaceAll("&[^;]+?;", ""); //Replace invalid HTML characters
//print xml
System.out.println("The XML is:\n\n" + xmlString);
OutputStream out = new FileOutputStream(dir.getSearchFileOutputDirectory() + "\\" + "output.xml");
//Write the XML to disk
out.write(xmlString.getBytes("ISO-8859-1"));
out.close();
,如果我运行这个在NetBeans中,XML文件呈现完美的Chrome,IE和Firefox中。但是,一旦我清理并构建代码,然后运行独立的JAR文件,浏览器报告文件中的编码错误,并且无法呈现它。
事情是他们在失败的行并不真正包含任何不寻常的东西,只是标准的ASCII字符,我可以看到。
任何人都可以阐明为什么这可能会发生?我必须明天演示代码,现在我正陷入恐慌之中,为什么它突然做了这个奇怪的事情......
任何输入将不胜感激。
感谢
托尼
你是否对每种方式生成的文件做了差异? –