javax.xml.stream.XMLStreamException:
java.net.MalformedURLException我今天学习了用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();
}
}
}
}
这是我的工程目录,,大家帮我看一下吧,谢谢了。。等下 还有我报的错误
------解决方案--------------------应该是你读取不到books.xml造成的,books.xml放到src根目录看看。