本文介绍了将InputStream转换为FileInputStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读这篇文章如何在转换时将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.

我需要执行此操作,才能从调用中获取FileChannelObject.class.getResourceAsStream(resourceName);

I need to do this to get the FileChannel from a call toObject.class.getResourceAsStream(resourceName);

推荐答案

您不能在没有基本写入文件的情况下进行操作.除非有文件,否则不会有FileInputStreamFileChannel.如果可能的话,请确保您的代码对输入源是不可知的-根据InputStreamByteChannel(或最适合的通道类型)进行设计.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 08:03
查看更多