FileInputStream to byte array in Android application

前端 未结 4 1222
梦如初夏
梦如初夏 2020-12-17 16:00

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

4条回答
  •  醉梦人生
    2020-12-17 16:15

    You can pre-allocate the byte array using

    int size = context.getFileStreamPath(filename).length();
    

    This way, you will avoid allocating memory chunks every time your ByteArrayOutputStream fills up.

提交回复
热议问题