我先读取了xml配置文件再在里面修改了一些节点值再保存xml文档,就出现如下问题,
第一个是<?xml version="1.0" encoding="gb2312"?>中的encoding="utf-8"了
第二个是当我再次读这个xml文档时就报错了如下所示:
org.dom4j.DocumentException: Error on line 1 of document file:///C:/Documents and Settings/Administrator/jbproject/xml/src/jieMian/my_config.xml : 字符转换错误:“Unconvertible UTF-8 character beginning with 0xbc”(行号可能太小)。 Nested exception: 字符转换错误:“Unconvertible UTF-8 character beginning with 0xbc”(行号可能太小)。
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.dom4j.io.SAXReader.read(SAXReader.java:264)
at jieMian.xmlManager.getXmlConfig(xmlManager.java:88)
at jieMian.XmlManagerDialog.init(XmlManagerDialog.java:102)
at jieMian.XmlManagerDialog.<init>(XmlManagerDialog.java:36)
at jieMian.XmlManagerDialog.<init>(XmlManagerDialog.java:44)
at jieMian.XmlManagerDialog_butn2_actionAdapter$1.run(XmlManagerDialog.java:183)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
Nested exception:
org.xml.sax.SAXParseException: 字符转换错误:“Unconvertible UTF-8 character beginning with 0xbc”(行号可能太小)。
at org.apache.crimson.parser.InputEntity.fatal(InputEntity.java:1100)
at org.apache.crimson.parser.InputEntity.fillbuf(InputEntity.java:1072)
at org.apache.crimson.parser.InputEntity.isXmlDeclOrTextDeclPrefix(InputEntity.java:914)
at org.apache.crimson.parser.Parser2.maybeXmlDecl(Parser2.java:1150)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:620)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:333)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.dom4j.io.SAXReader.read(SAXReader.java:264)
at jieMian.xmlManager.getXmlConfig(xmlManager.java:88)
at jieMian.XmlManagerDialog.init(XmlManagerDialog.java:102)
at jieMian.XmlManagerDialog.<init>(XmlManagerDialog.java:36)
at jieMian.XmlManagerDialog.<init>(XmlManagerDialog.java:44)
at jieMian.XmlManagerDialog_butn2_actionAdapter$1.run(XmlManagerDialog.java:183)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
有没有做过的,要怎么解决啊,急啊
怎样修改<?xml version="1.0" encoding="gb2312"?>
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- geshula 2009-02-24 20:36关注
[code="java"]
SAXReader reader=new SAXReader();
Document doc=reader.read(new File("F:\temp\test2.xml"));
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("gbk");//修改编码
XMLWriter writer=new XMLWriter(new FileOutputStream("F:\temp\test3.xml"),format);
writer.write(doc);
writer.close();
[/code]本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 用verilog实现tanh函数和softplus函数
- ¥15 求京东批量付款能替代天诚
- ¥15 slaris 系统断电后,重新开机后一直自动重启
- ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
- ¥15 关于vue2中methods使用call修改this指向的问题
- ¥15 idea自动补全键位冲突
- ¥15 请教一下写代码,代码好难
- ¥15 iis10中如何阻止别人网站重定向到我的网站
- ¥15 滑块验证码移动速度不一致问题
- ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含