How to read a file as a byte array in Scala

前端 未结 7 1229
情话喂你
情话喂你 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:20

    This should work (Scala 2.8):

    val bis = new BufferedInputStream(new FileInputStream(fileName))
    val bArray = Stream.continually(bis.read).takeWhile(-1 !=).map(_.toByte).toArray
    

提交回复
热议问题