/**
* 这个方法使用XMLOutputter将JDom Document对象输出到文件
* @param doc 将要输出的JDom Document对象
* @param filePath 将要输出到的磁盘路径
* @param newline 是否换行
* @param encoding 编码方式
*/
public static void OutputToFile(
Document myDocument,
String filePath,
boolean newline,
String encoding) {
try {
XMLOutputter outputter = new XMLOutputter(" ", newline, encoding);
FileWriter writer = new FileWriter(filePath);
outputter.output(doc, writer);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
* 这个方法使用XMLOutputter将JDom Document对象输出到文件
* @param doc 将要输出的JDom Document对象
* @param filePath 将要输出到的磁盘路径
* @param newline 是否换行
* @param encoding 编码方式
*/
public static void OutputToFile(
Document myDocument,
String filePath,
boolean newline,
String encoding) {
try {
XMLOutputter outputter = new XMLOutputter(" ", newline, encoding);
FileWriter writer = new FileWriter(filePath);
outputter.output(doc, writer);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
XMLOutputter outputter = new XMLOutputter(" ", newline, encoding);
*******************************************************************
下面是api文档中给出的三个构造函数的说明,没有大哥你说的那样的构造啊
Constructor Summary
XMLOutputter()
This will create an XMLOutputter with the default Format matching Format.getRawFormat().
XMLOutputter(Format format)
This will create an XMLOutputter with the specified format characteristics.
XMLOutputter(XMLOutputter that)
This will create an XMLOutputter with all the options as set in the given XMLOutputter.
userFormat.setIndent(indent);
if (newlines == false) userFormat.setIndent(null);
userFormat.setEncoding(encoding);
}我用的是jdom b10
Format format = Format.getPrettyFormat();
format.setEncoding("GBK");
XMLOutputter outp = new XMLOutputter(format);
outp.output(xmlDocument, new FileOutputStream("c:\\subject_data3_gbk.xml")); //输出XML文档
其中Format类的构在方法是private的必须用下面三个方法实例化
getRawFormat() (no whitespace changes),
getPrettyFormat() (whitespace beautification),
getCompactFormat() (whitespace normalization).
并且实例化的Format再输出时都不一样。