How to read a file as a byte array in Scala

前端 未结 7 1200
情话喂你
情话喂你 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))
    
    0 讨论(0)
提交回复
热议问题