In Java reading the properties configuration file , we know how to read the properties configuration file. Here we know how to get the file path under the resoures file. Before getting the path of the properties configuration file, we used the Thread method as follows:
In fact, we can also obtain the path under the resources folder in the form of Thread, as follows
Thread.currentThread().getContextClassLoader().getResource("…").getPath()
It should be noted that the static folder cannot be empty, otherwise it may report that the null pointer is abnormal, because the empty folder is ignored during packaging, here we can view through the target package
In addition to this, we can also use many other methods, as follows:
this.getClass().getClassLoader().getResource("…").getPath()
XXX.class.getClassLoader().getResource("…").getPath()
ClassLoader.getSystemClassLoader().getResource("…").getPath()
ClassLoader.getSystemResource("…").getPath()