JSP学习笔记(一百一十六): 读取Jar包中的资源文件

读取URI的方法:

URL fileURL=this.getClass().getResource("/com/comp/resource/simple.jpg");
System.out.println(fileURL.getFile());  

 

读取Stream流的方法(这个比较有用):

InputStream inputStream = this.getClass().getResourceAsStream("/com/comp/resource/simple.jpg");

如果使用了xwork2,还可以这么写:

InputStream inputStream = ClassLoaderUtil.getResourceAsStream("com/comp/resource/sample.jpg", null);
posted @ 2010-06-08 17:37  魔豆  阅读(537)  评论(0编辑  收藏  举报