在maven工程中,如果想获取src/main/resources 的路径,方法1Thread.currentThread().getContextClassLoader(). getResource(".").getPath() 这样获取出来的路径是在target/classes 这个目录下。方法2:this.getClass().getClassLoader().getResource("config.properties").getPath();
在maven工程中,如果想获取src/main/resources 的路径,方法1Thread.currentThread().getContextClassLoader(). getResource(".").getPath() 这样获取出来的路径是在target/classes 这个目录下。方法2:this.getClass().getClassLoader().getResource("config.properties").getPath();