美文网首页
FileInputStream如何正确使用Jar包中的资源文件

FileInputStream如何正确使用Jar包中的资源文件

作者: muco | 来源:发表于2016-09-18 18:00 被阅读1062次

基本思路

A resource contained within a JAR file is not itself a file, and cannot be read using a FileInputStream. If you have code that absolutely requires a FileInputStream, then you'll need to extract the data using getResourceAsStream(), copy it into a temporary file, then pass a FileInputStream for that temporary file to your code.

-- <cite>StackOverFlow</cite>

翻译:
由于包含在Jar包中的资源文件本身不是一个文件,所以FileInputStream不能够直接读取Jar中文件的内容,而如果没有其他选择必须使用FileInputStream(比如你使用的第三方库就是使用FileInputStream,需要你传递文件路径)的情况下,你可以考虑通过getResourceAsStream()先获取文件流,然后创建一个系统临时文件,把临时文件传递给FileInputStream使用。

相关文章

网友评论

      本文标题:FileInputStream如何正确使用Jar包中的资源文件

      本文链接:https://www.haomeiwen.com/subject/gnlgettx.html