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 array with scala libraries - can someone help me with that?
Java 7:
import java.nio.file.{Files, Paths}
val byteArray = Files.readAllBytes(Paths.get("/path/to/file"))
I believe this is the simplest way possible. Just leveraging existing tools here. NIO.2 is wonderful.
This should work (Scala 2.8):
val bis = new BufferedInputStream(new FileInputStream(fileName))
val bArray = Stream.continually(bis.read).takeWhile(-1 !=).map(_.toByte).toArray
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With