我目前正在将 XML 文档输出到 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 风格的行尾。我怎么能做到这一点?