问题描述
我已阅读这篇文章如何在转换时将InputStream转换为FileInputStream 将InputStream转换为FileInputStream.但是,如果您使用的是jar文件中的资源,答案将不起作用.还有另一种方法吗?
I have read this post How to convert InputStream to FileInputStream on converting a InputStream into a FileInputStream. However, the answer does not work if you are using a resource that is in a jar file. Is there another way to do it.
我需要执行此操作,才能从调用中获取FileChannel
Object.class.getResourceAsStream(resourceName);
I need to do this to get the FileChannel
from a call toObject.class.getResourceAsStream(resourceName);
推荐答案
您不能在没有基本写入文件的情况下进行操作.除非有文件,否则不会有FileInputStream
或FileChannel
.如果可能的话,请确保您的代码对输入源是不可知的-根据InputStream
和ByteChannel
(或最适合的通道类型)进行设计.
You can't, without basically writing to a file. Unless there's a file, there can't be a FileInputStream
or a FileChannel
. If at all possible, make sure your code is agnostic to the input source - design it in terms of InputStream
and ByteChannel
(or whatever kind of channel is most appropriate).
这篇关于将InputStream转换为FileInputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!