WEB应用中 取路径

取Servlet上下文路径,取WebContent(WebRoot)的路径

1、String path = request.getRealPath("/cfg.xml") (有警告,不建议使用)

2、String path = request.getSession().getServletContext().getRealPath("/cfg.xml");

-----------------------------------------------------
取类路径

1、String path = this.getClass().getClassLoader().getResource("/").getPath();

2、InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);(得到流)

3、ReadCard.class.getResourceAsStream( "/com/a.txt"); //在/com/目录下找文件

4、ReadCard.class.getResourceAsStream( "a.txt"); //在ReadCard类所在目录找文件

5、inputStream = ReadCard.class.getResource("a.txt").openStream();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值