首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

stax 解析xml文件时老是报错,解决方法

2013-12-10 
stax 解析xml文件时老是报错,我今天学习了用stax解析xml文件,怎么老是报这个错误,我给大家好好看看一下我

stax 解析xml文件时老是报错,
我今天学习了用stax解析xml文件,怎么老是报这个错误,我给大家好好看看一下我的代码

package com.daijianwei.stax;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.junit.Test;

public class TestStax {

@Test
public void test01() {
XMLInputFactory factory = XMLInputFactory.newInstance();
InputStream is = null;
try {
is = TestStax.class.getClassLoader().getResourceAsStream("books.xml");
XMLStreamReader reader = factory.createXMLStreamReader(is);
while (reader.hasNext()) {
System.out.println(reader.next());
}
} catch (XMLStreamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (is != null)
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

stax 解析xml文件时老是报错,解决方法stax 解析xml文件时老是报错,解决方法
[解决办法]
应该是你读取不到books.xml造成的,books.xml放到src根目录看看。

热点排行