要取编译后的路径,而不是你看到的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