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
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…