How to read a file as a byte array in Scala

前端 未结 7 1228
情话喂你
情话喂你 2020-12-02 08:31

I can find tons of examples but they seem to either rely mostly on Java libraries or just read characters/lines/etc.

I just want to read in some file and get a byte

7条回答
  •  悲&欢浪女
    2020-12-02 09:26

    You can use the Apache Commons Compress IOUtils

    import org.apache.commons.compress.utils.IOUtils
    
    val file = new File("data.bin")
    IOUtils.toByteArray(new FileInputStream(file))
    

提交回复
热议问题