0

I cached a Json file as byte array and want to read it afterwards with the JsonReader.

However, the JsonReader takes a Reader as input parameter.

How can I convert me byte array to a Reader and is it worth doing so, or is there a straighter way of caching the InputStream of the Json file and read it afterwards by the JsonReader?

Looking forward to your responses!

Poweranimal
  • 1,622
  • 3
  • 12
  • 16

1 Answers1

1

You can chain ByteArrayInputStream and InputStreamReader to get the Reader object, e.g.:

byte[] array = new byte[50];//json file
Reader reader = new InputStreamReader(new ByteArrayInputStream(array));
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102