FileInputStream to byte array in Android application

前端 未结 4 1244
梦如初夏
梦如初夏 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:28

    This is the easiest way

    FileInputStream fis =  openFileInput(fileName);
    
    byte[] buffer =   new byte[(int) fis.getChannel().size()];
    
    fis.read(buffer);
    

提交回复
热议问题