org.xml.sax.SAXParseException:文件过早结束
这是我的 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<settings></settings>
,我的方法如下所示
public void load( String fileName ) {
...
Document xmlDocument = null;
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try
{
builder = dbFactory.newDocumentBuilder();
xmlDocument = builder.parse(new File (fileName));
}
catch( Exception e )
{
Log.write(e);
}
...
}
当我调用我的方法时,我收到以下信息:
[task] org.xml.sax.SAXParseException: Premature end of file.
[task] at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
[task] at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
[task] at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
[task] at MyClass.load(MyClass.java:49)
我完全困惑了。
感谢您的任何想法。
-西里尔
this is my xml file
<?xml version="1.0" encoding="utf-8"?>
<settings></settings>
and my method is shown below
public void load( String fileName ) {
...
Document xmlDocument = null;
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try
{
builder = dbFactory.newDocumentBuilder();
xmlDocument = builder.parse(new File (fileName));
}
catch( Exception e )
{
Log.write(e);
}
...
}
When I invoke my method I receive the following:
[task] org.xml.sax.SAXParseException: Premature end of file.
[task] at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
[task] at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
[task] at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
[task] at MyClass.load(MyClass.java:49)
I am completely confused.
Thanks for any ideas.
-Cyril
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题可能存在于struts.xml 文件中。以下行必须包含在 struts.xml 文件中。
并且
标签必须写入到 Sturts.xml 文件内的
标签内。problem may exist in struts.xml file. The following line must be included in struts.xml file.
and
<package>
tag must be written inside<struts>
tag inside sturts.xml file.确保内容类型
content-type:text/xml;字符集=utf-8
Make sure the content type
content-type:text/xml; charset=utf-8