Quantcast
Channel: Read entire file in Scala? - Stack Overflow
Viewing all articles
Browse latest Browse all 20

Answer by elm for Read entire file in Scala?

$
0
0

For emulating Ruby syntax (and convey the semantics) of opening and reading a file, consider this implicit class (Scala 2.10 and upper),

import java.io.Filedef open(filename: String) = new File(filename)implicit class RichFile(val file: File) extends AnyVal {  def read = io.Source.fromFile(file).getLines.mkString("\n")}

In this way,

open("file.txt").read

Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>