Android : How to read file in bytes?

前端 未结 8 1033
逝去的感伤
逝去的感伤 2020-11-27 15:25

I am trying to get file content in bytes in Android application. I have get the file in SD card now want to get the selected file in bytes. I googled but no such success. Pl

8条回答
  •  时光说笑
    2020-11-27 15:54

    The easiest solution today is to used Apache common io :

    http://commons.apache.org/proper/commons-io/javadocs/api-release/org/apache/commons/io/FileUtils.html#readFileToByteArray(java.io.File)

    byte bytes[] = FileUtils.readFileToByteArray(photoFile)
    

    The only drawback is to add this dependency in your build.gradle app :

    implementation 'commons-io:commons-io:2.5'
    

    + 1562 Methods count

提交回复
热议问题