我正在尝试从jar文件中访问资源.资源位于jar的同一目录中.
my-dir:
tester.jar
test.jpg
Run Code Online (Sandbox Code Playgroud)
我尝试了不同的东西,包括以下内容,但每次输入流为空时:
[1]
String path = new File(".").getAbsolutePath();
InputStream inputStream = this.getClass().getResourceAsStream(path.replace("\\.", "\\") + "test.jpg");
Run Code Online (Sandbox Code Playgroud)
[2]
File f = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
InputStream inputStream = this.getClass().getResourceAsStream(f.getParent() + "test.jpg");
Run Code Online (Sandbox Code Playgroud)
你能给我一些提示吗?谢谢.