Scala File Operation
Jump to navigation
Jump to search
A Scala File Operation is a Scala operation that is a file operation.
References
Examples
- Reading & Writing Files
Just reading from a file
val lines = scala.io.Source.fromFile("myfile.txt").mkString // leaves the file open
import scala.io.Source._ ;
// slurp the file
val source1 = fromFile("myfile.txt", "utf-8") ;
val lines = source1.getLines mkString "\n" ;
source1.close() ; // good practice
// or create an iterator
val source2 = fromFile("myfile.txt", "utf-8")
source2.foreach{
print
}
// tab separated file
val source3 = fromFile("myfile.tsv", "utf-8")
source3.foreach {
print _.toArray ;
}
source3.close ;