[转]Maven项目读取src.main.resources下的文件

要取编译后的路径,而不是你看到的src/main/resources的路径。如下:

URL url = MyTest.class.getClassLoader().getResource("userFile.properties");

File file = new File(url.getFile());

或者

InputStream is = MyTest.class.getClassLoader().getResourceAsStream("userFile.properties");

链接:https://blog.csdn.net/totally123/article/details/72901076

posted @ 2018-07-25 10:05  zifeiy  阅读(267)  评论(0编辑  收藏  举报