[转]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

猜你喜欢

转载自www.cnblogs.com/zifeiy/p/9364338.html