1

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?

Nikem
  • 5,716
  • 3
  • 32
  • 59
pythonic
  • 20,589
  • 43
  • 136
  • 219

1 Answers1

2

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)))
pythonic
  • 20,589
  • 43
  • 136
  • 219