使用 JsonReader 将缓存的 Json 文件读取为 ByteArray

Posted

技术标签:

【中文标题】使用 JsonReader 将缓存的 Json 文件读取为 ByteArray【英文标题】:Read cached Json file as ByteArray with JsonReader 【发布时间】:2017-04-15 19:52:54 【问题描述】:

我将一个 Json 文件缓存为字节数组,然后想用JsonReader 读取它。

但是,JsonReader 将Reader 作为输入参数。

如何将字节数组转换为 Reader,是否值得这样做,或者是否有更直接的方法来缓存 Json 文件的 InputStream 并在之后由 JsonReader 读取?

期待您的回复!

【问题讨论】:

【参考方案1】:

您可以链接ByteArrayInputStreamInputStreamReader 以获取Reader 对象,例如:

byte[] array = new byte[50];//json file
Reader reader = new InputStreamReader(new ByteArrayInputStream(array));

【讨论】:

完美!这正是我一直在寻找的。非常感谢!

以上是关于使用 JsonReader 将缓存的 Json 文件读取为 ByteArray的主要内容,如果未能解决你的问题,请参考以下文章