java 将 ByteArrayOutputStream 转换为 FileInputStream
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17595891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
convert ByteArrayOutputStream to FileInputStream
提问by Uwe Plonus
I have stream saved in ByteArrayOutputStream
. now I want to to read that in FileInputStream
. how Can I do that?
我已将流保存在ByteArrayOutputStream
. 现在我想在FileInputStream
. 我怎样才能做到这一点?
it's my outputStream.
这是我的输出流。
...
OutputStream out = new ByteArrayOutputStream();
...
now how to read that, from FileInputStream
?
现在如何阅读,从FileInputStream
?
回答by Uwe Plonus
You can create a ByteArrayInputStream
with
您可以创建一个ByteArrayInputStream
与
InputStream is = new ByteArrayInputStream(bos.toByteArray());
and then read from this InputStream
.
然后从这里开始阅读InputStream
。
If your interface only accepts a FileInputStream
then the interface is broken...
如果您的接口只接受 aFileInputStream
那么接口坏了...
If, at all, an interface only works with files it should accept a File
else it should use an InputStream
.
如果接口只适用于文件,它应该接受File
其他文件,否则它应该使用InputStream
.
Also if you use threads you can use PipedInputStream
and PipedOutputStream
directly between the threads.
此外,如果您使用线程,则可以直接在线程之间使用PipedInputStream
和PipedOutputStream
。