我将一些大数据以 xml 格式加载到程序中的字符串中(来自 mysql),当我将此字符串保存到 out.xml 中时,仅存储了大约 500 条记录。 如何将大字符串或其他数据保存到 xml 格式或任何其他格式的文件中?
这是我的代码:
String xmlString = doExportIntoString();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
InputSource source = new InputSource(new StringReader(xmlString));
Document document =factory.newDocumentBuilder().parse(source);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
Result result = new StreamResult(new File("C:\\xmlFile.xml"));
Source s = new DOMSource(document);
transformer.transform(s, result);
最佳答案
这是上面代码的正确版本:
BufferedWriter out;
try {
out = new BufferedWriter(new FileWriter("out.txt"));
out.write("aString");
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (out != null) {
try { out.close(); } catch (IOException e) {}
}
}
关于java - java中如何将大字符串保存到xml文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9470235/