1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
public class ResourceTest {
public static void main(String[] args) { String a1 = ResourceTest.class.getResource("/com/test/Resource.class").getPath(); String a2 = ResourceTest.class.getResource("Resource.class").getPath(); String a3 = ResourceTest.class.getResource("/application.properties").getPath(); String a4 = ResourceTest.class.getResource("../../application.properties").getPath(); String a5 = ResourceTest.class.getResource("/conf/config.json").getPath(); String a6 = ResourceTest.class.getResource("../../conf/config.json").getPath();
String b1 = ResourceTest.class.getClassLoader().getResource("com/test/Resource.class").getPath(); String b2 = ResourceTest.class.getClassLoader().getResource("application.properties").getPath(); String b3 = ResourceTest.class.getClassLoader().getResource("conf/config.json").getPath();
String c1 = ClassLoader.getSystemClassLoader().getResource("com/test/Resource.class").getPath(); String c2 = ClassLoader.getSystemClassLoader().getResource("application.properties").getPath(); String c3 = ClassLoader.getSystemClassLoader().getResource("conf/config.json").getPath();
String d1 = ClassLoader.getSystemResource("com/test/Resource.class").getPath(); String d2 = ClassLoader.getSystemResource("application.properties").getPath(); String d3 = ClassLoader.getSystemResource("conf/config.json").getPath();
String e1 = Thread.currentThread().getContextClassLoader().getResource("com/test/Resource.class").getPath(); String e2 = Thread.currentThread().getContextClassLoader().getResource("application.properties").getPath(); String e3 = Thread.currentThread().getContextClassLoader().getResource("conf/config.json").getPath(); } }
|