请问getClass().getResourceAsStream(fileName)中的fileName可以用绝对路径吗?

javaCandelaboy 2004-06-25 08:59:03
请问getClass().getResourceAsStream(fileName)中的fileName可以用绝对路径吗?
我用了

Properties prop = new Properties();
prop.load(getClass().getResourceAsStream( "/props/feconfig.properties"));
是可以的,但是
prop.load(getClass().getResourceAsStream("\\props\\feconfig.properties"));
好像不行,不知道可以吗?为什么呢?
...全文
211 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qlampskyface 2004-06-25
  • 打赏
  • 举报
回复
将\\换成/再试试
tmpx 2004-06-25
  • 打赏
  • 举报
回复
This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/".
javaCandelaboy 2004-06-25
  • 打赏
  • 举报
回复
上面写错了,是:

prop.load(getClass().getResourceAsStream("D:\\props\\feconfig.properties"));
好像不行,不知道可以吗?为什么呢?

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧