日期:2014-05-20 浏览次数:20644 次
public class ParseTest{我要用到xml文件的绝对路径,应该怎么做?求指导。
public static void main(String[] args) {
SaxParseService sax = new SaxParseService();
//放在D盘就找不到资源报错了
InputStream input = SaxParseService.class.getClassLoader().getResourceAsStream("D:/book.xml");
//放在src下能正常输出
// InputStream input = SaxParseService.class.getClassLoader().getResourceAsStream("book.xml");
List<Book> books=null;
try {
books = sax.getBooks(input);
} catch (Exception e) {
e.printStackTrace();
}
for(Book book : books){
System.out.println(book.toString());
}
}
}
InputStream input = SaxParseService.class.getClassLoader().getResourceAsStream("D:/book.xml");
InputStream input = new FileInputStream("D:/book.xml");