从.jar文件夹中读取文件 [英] Read a file from inside the .jar folder
本文介绍了从.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.
这篇关于从.jar文件夹中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文