Read Write Files
A Path are both Input and Output objects as well as Seekable so all read/write options available through those are also possible directly on Path objects
Safe Read Write
Safe way to read and write a file. Normal try-catch will also work, scala.util.control.Exception is nice when used with an API that takes Either or Option.
import scalax.file.{
FileOps, Path, NotFileException}
import java.io.FileNotFoundException
import scala.util.control.Exception._
// see codec examples in scala io core for details on why there is an implicit codec here
implicit val codec = scalax.io.Codec.UTF8
val file: FileOps = Path("file")
val result:Either[Throwable,String] = catching (classOf[NotFileException],
classOf[FileNotFoundException]) either { file.slurpString}
result match {
case Left(error) => println("oops not a file maybe a directory: "+error.getMessage)
case Right(data) => println (data)
}