以下是代码:
public class t {
private DocumentBuilderFactory dbf = null; // 程序使用的变量
private DocumentBuilder db = null; // 程序使用的变量
private XmlDocument doc = null; // 程序使用的变量
private Element root; // 程序使用的变量

public void a(String file) throws Exception
{
dbf = DocumentBuilderFactory.newInstance();
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException pce) {
System.err.println(pce);
} try {
doc = (XmlDocument)db.parse(new File(file));
} catch (DOMException dom) {
System.err.println(dom.getMessage());
} catch (IOException ioe) {
System.err.println(ioe);
} catch (SAXException sax) {
System.err.println(sax.getMessage());
} catch (Exception e) {
System.err.println(e.getMessage());
} root = doc.getDocumentElement(); System.out.println(this.root);
FileOutputStream outStream = new FileOutputStream(file);
OutputStreamWriter outWriter = new OutputStreamWriter(outStream);
doc.write(outWriter, "GB2312");
outWriter.close();
outStream.close();

}
}
执行后打开文件,发现每两行间多了一行,内容是一个或两个 tab 符,数量和深度相同。
有遇到过的吗?读的时候怎么指定编码方式?