java中获取src同级目录下其他文件夹配置文件的方法

代码结构如下:

demo

--src

--conf

----aaa.properties

 1 Properties props = new Properties();
 2 try {
 3     String url = RemoteFilter.class.getClassLoader().getResource("/").toURI().getPath()+"aaa.properties";
 4     InputStream in = new FileInputStream(new File(url));
 5     props.load(in);
 6 } catch (IOException e) {
 7     e.printStackTrace();
 8 } catch (URISyntaxException e) {
 9     e.printStackTrace();
10 }
11 
12 String value = props.getProperty("key");

 

posted @ 2019-04-16 09:57  Little-Coder  阅读(2861)  评论(0)    收藏  举报