fix bug 修复 ClassLoader 读取不到自身 jar 文件内的配置文件

This commit is contained in:
wangxiang
2023-07-30 10:55:28 +08:00
parent 3f049c9393
commit d4f5b8af58
2 changed files with 3 additions and 10 deletions

View File

@@ -23,17 +23,10 @@ public class ClassLoader {
public JarFile jarFile = null; public JarFile jarFile = null;
static { static {
URL resource = ClassLoader.class.getResource("/"); InputStream is = ClassLoader.class.getResourceAsStream("/haidnorJVM.properties");
String path = resource.getPath();
FileInputStream fis;
try {
fis = new FileInputStream(path + "/haidnorJVM.properties");
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Properties properties = new Properties(); Properties properties = new Properties();
try { try {
properties.load(fis); properties.load(is);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@@ -142,7 +142,7 @@ public class TestJVM {
runMainClass(demo_finally_2.class); runMainClass(demo_finally_2.class);
} }
@Test @Test(expected = ArithmeticException.class)
public void demo_finally_3() throws Exception { public void demo_finally_3() throws Exception {
runMainClass(demo_finally_3.class); runMainClass(demo_finally_3.class);
} }