转换的InputStream的FileInputStream的Apache POI不工作 [英] Converting InputStream to FileInputStream Not Working for Apache POI
问题描述
我试图访问从我RES /原始文件夹中的Excel文件,我知道,你真的只能做到这一点使用的InputStream;然而,XSSFWorkbook命令中的Apache POI只需要FileInputStreams而不是InputStreams:有没有办法做到这一点?我用下面的code尝试,但走这条错误:显示java.lang.NullPointerException:尝试调用虚拟方法java.net.URI中java.net.URL.toURI()上空对象引用
下面是code,我试过用:
插件URL = this.getClass()的getResource(ncaa.xlsx);
的FileInputStream文件=新的FileInputStream(新文件(ins.toURI()));
XSSFWorkbook工作簿=新XSSFWorkbook(文件);
有没有办法做到这一点?
块引用>复制出来的原始资源到一个文件,然后打开该文件,并交给了
的FileInputStream
到库中。
我已经尝试使用以下
块引用>
的getResource()
无关与Android的资源。要访问的InputStream
上的原始资源,使用getResources()。openRawResource()
,叫上你的活动
或其他方便的上下文
。I am trying to access an excel file from my res/raw folder, and I know that you can only really do this using an InputStream; however, the XSSFWorkbook commands in Apache POI only take FileInputStreams and not InputStreams: is there any way to do this? I've tried using the following code but go this error:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.net.URI java.net.URL.toURI()' on a null object reference
Here is the code I've tried using:
URL ins = this.getClass().getResource("ncaa.xlsx"); FileInputStream file = new FileInputStream(new File(ins.toURI())); XSSFWorkbook workbook = new XSSFWorkbook(file);
解决方案is there any way to do this?
Copy the raw resource out to a file, then open the file and hand the
FileInputStream
over to the library.I've tried using the following
getResource()
has nothing to do with Android resources. To access anInputStream
on a raw resource, usegetResources().openRawResource()
, called on yourActivity
or other handyContext
.这篇关于转换的InputStream的FileInputStream的Apache POI不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!