以下是代码:
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 符,数量和深度相同。
有遇到过的吗?读的时候怎么指定编码方式?
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 符,数量和深度相同。
有遇到过的吗?读的时候怎么指定编码方式?
解决方案 »
- 关于Vector的一个问题
- 纯J2SE中如何织入事务或日志
- 点击重新登录,跳转到登陆页面并且清空session,怎末实现
- how to destory a stateful session bean when network is unavailable
- luence 2.3.2 建索引问题
- 系统构建高性能J2EE应用的五种核心策略
- Hibernate一对多异常问题(在线等)
- struts中标签问题
- tomcat不支持汉字!!!!
- 装上JDataConnection Server之后,在数据源ODBC中的驱动程序列表中没有JDBC驱动算不算问题,高分求解!
- 求助!hibernate中问题,等待高手~~~~
- web应用中如何做柱状图和折线图?
再转成String,去其空格...