星空网 > 软件开发 > Java

javaweb中加载外部文件的三种方式

1.request.getSession().getServletContext().getResourceAsStream("/WEB-INF/classes/a.txt"");

  / 相对对于项目的根路径

 

2.getClass().getClassLoader().getResourceAsStream("/a.txt")

  / 不管有没有'/' 都相对于classpath路径(/WEB-INF/classes/)

 

3.getClass().getResourceAsStream("/a.txt")

 如果有'/'相对于classpath路径,如果没有相对于class文件对应的位置。

 

注:这里的classpat指的是web项目发布之后/WEB-INF/classes/

eclipse中查看方法调用的快捷键:control+alt+h

右键:Open Call Hierarchy




原标题:javaweb中加载外部文件的三种方式

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

贷款服务:https://www.goluckyvip.com/tag/8060.html
阿里巴巴卖家:https://www.goluckyvip.com/tag/8061.html
买家评分:https://www.goluckyvip.com/tag/8062.html
产品属性设置:https://www.goluckyvip.com/tag/8063.html
数据管家:https://www.goluckyvip.com/tag/8064.html
客户询问:https://www.goluckyvip.com/tag/8065.html
在古巴做游轮 古巴旅游项目:https://www.vstour.cn/a/363194.html
西藏旅游攻略自驾游需要多少天 去西藏旅游自驾游要多久时间:https://www.vstour.cn/a/363195.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流