1. 程式人生 > >java載入資原始檔方式總結

java載入資原始檔方式總結

 // 同一包下
URL u2 = ClassLoader.getSystemResource("c1.xml");
URL u3 = ClassLoader.getSystemClassLoader().getResource("c1.xml");
System.out.println(u2.toString());
System.out.println(u3.toString());
// 指定包下且不同包
URL u = ClassLoader.getSystemResource("com/test2/c1.xml");
URL u1 = ClassLoader.getSystemClassLoader().getResource(
"com/test2/c1.xml");
System.out.println(u.toString());
System.out.println(u1.toString());
// 從根路徑開始
URL u4 = ClassLoader.getSystemResource("c1.xml");
URL u5 = ClassLoader.getSystemClassLoader().getResource("c1.xml");
System.out.println(u4.toString());
System.out.println(u5.toString());