Reputation: 21615
I am currently using the following to do this.
val string = scala.io.Source.fromFile(filePath).mkString
However, I've noticed that it is quite slow. Is there any better (in terms of speed) method to read the whole file into a string?
Upvotes: 1
Views: 3286
Reputation: 21615
I used the following. This is much faster than my previous approach.
import java.nio.file.Files
import java.nio.file.Paths
val string = new String(Files.readAllBytes(Paths.get(filePath)))
Upvotes: 2