从.jar文件夹中读取文件
问题描述:
我需要以这种方式读取jar文件夹中的文件:
I need to read the file, that is inside the jar folder in this way:
DataSource coverdata = new FileDataSource(new File("here is the path"));
如何获取确切路径?我正在使用一个库,因此访问文件的唯一方法是new File()
,没有输入流.
How do I get the exact path? I am using a library, so the only way I can acces file is new File()
, no inputstreams.
答
调用ClassLoader.getResourceAsStream()::InputStream
或ClassLoader.getResource()::URL
.
请参阅:
包含请求文件的JAR文件必须在类路径中.
The JAR file containing the requested file must be in the classpath.