读取maven项目resources路径下的文件

适用于在IDE中运行项目

方式一:

URL url = 类名.class.getClassLoader().getResource("conf.properties");
File file = new File(url.getFile());

方式二:

InputStream is = 类名.class.getClassLoader().getResourceAsStream("conf.properties");

 

- - 补充 2020年11月18日 - - - - - - - - - - - - - - - - - - - - - - - - - - -

获取程序运行的根路径:

String path = 类名.class.getResource("/").getPath();

 

posted @ 2019-09-03 17:13  李传炎  阅读(1505)  评论(0)    收藏  举报