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.
More Related Contents:
- What is the motivation for Scala assignment evaluating to Unit rather than the value assigned?
- Strange behaviour of the Array type with `==` operator
- How to define “type disjunction” (union types)?
- What is the difference between a var and val definition in Scala?
- How to define partitioning of DataFrame?
- What is the apply function in Scala?
- How do I apply the enrich-my-library pattern to Scala collections?
- In Scala, what is an “early initializer”?
- Case class equality in Apache Spark
- How to model type-safe enum types?
- Scala: List[Future] to Future[List] disregarding failed futures
- Filling gaps in timeseries Spark
- How to create a TypeTag manually?
- Weird behavior trying to convert case classes to heterogeneous lists recursively with Shapeless
- val and object inside a scala class?
- Implicit keyword before a parameter in anonymous function in Scala
- Parsing multiline records in Scala
- In Scala 2, type inference fails on Set made with .toSet?
- What does a lazy val do?
- Explanation of fold method of spark RDD
- Play: How to implement action composition
- How to use third party libraries with Scala REPL?
- Applying an argument list to curried function using foldLeft in Scala
- How to split a sequence into two pieces by predicate?
- How to use IntelliJ with Play Framework and Scala
- Missing parameter type error by calling toSet?
- Spark column string replace when present in other column (row)
- scala f-bounded types explanation
- How to vectorize DataFrame columns for ML algorithms?