I have a FileInputStream created using Context.openFileInput(). I now want to convert the file into a byte array.
Unfortunately, I can't determine the size of the byte array required for FileInputStream.read(byte[]). The available() method doesn't work, and I can't create a File to check it's length using the specific pathname, probably because the path is inaccessible to non-root users.
I read about ByteArrayOutputStream, and it seems to dynamically adjust the byte array size to fit, but I can't get how to read from the FileInputStream to write to the ByteArrayOutputStream.
byte[]you supply toread(byte[])isn't intended to be the full size of whatever it is you're trying to read. It's a buffer that can hold the maximum number of bytes you're willing to read at a time, and each call toreadwill put some number of bytes into that buffer and return a number telling you how many bytes it put.