从字节数组创建一个文件 [英] Creating a File from byte array
本文介绍了从字节数组创建一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
File
作为输入的第三方库。我有一个字节数组
。 我不想把字节写到磁盘上。我想保留这个记忆。任何关于如何从提供的字节数组创建一个
File
的想法(不写入磁盘)?
解决方案
对不起,不可能。一个文件本质上是一个磁盘上的实体,除非你有一个RAM磁盘 - 但这不是你可以在Java中创建的。
这就是为什么API不应该基于File对象(或重载接受InputStream)。
So - I've got a third party library that needs a File
as input. I've got a byte array
.
I don't want to write the bytes to disk .. I'd like to keep this in memory. Any idea on how I can create a File
from the provided byte array
(without writing to disk)?
解决方案
Sorry, not possible. A File is inherently an on-disk entity, unless you have a RAM disk - but that's not something you can create in Java.
That's exactly the reason why APIs should not be based on File objects (or be overloaded to accept an InputStream).
这篇关于从字节数组创建一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文