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,313
  • 2
  • 30
  • 55
pythonic
  • 19,309
  • 37
  • 124
  • 208

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
  • 19,309
  • 37
  • 124
  • 208