从jar中读取资源文件
我想从我的jar中读取资源,如下所示:
File file;file = new File(getClass().getResource("/file.txt").toURI());BufferredReader reader = new BufferedReader(new FileReader(file)); //Read the file
并且它在Eclipse中运行时工作正常,但是如果我将它导出到jar中运行它就会出现IllegalArgumentException:
Exception in thread "Thread-2"java.lang.IllegalArgumentException: URI is not hierarchical
而且我真的不知道为什么,但经过一些测试我发现如果我改变了
file = new File(getClass().getResource("/file.txt").toURI());
至
file = new File(getClass().getResource("/folder/file.txt").toURI());
然后它的工作正好相反(它适用于jar而不是eclipse)。
我正在使用Eclipse,我的文件夹在一个类文件夹中。
开心每一天1111
梵蒂冈之花
慕容3067478
炎炎设计