在Windows上生成XML时,我目前输出的XML文档Java中的文件,如下所示使用Unix风格的行结束符:确保与Java
final Document xmldoc = toXMLDocument(docTheory);
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
DOMSource source = new DOMSource(xmldoc);
StreamResult result = new StreamResult(file);
transformer.transform(source, result);
然而,当在Windows上运行,这将产生输出, Windows风格的行尾。我希望不管操作系统如何生产Unix风格的行结尾。我如何做到这一点?
我不确定这是否是您的最佳解决方案,但'string.replaceAll(“\ r \ n”,“\ n”)'会做 –
如果答案有帮助,您可以[接受它](http ://meta.stackexchange.com/a/5235/227183)。 –