hayio
6/13/2015 - 12:10 PM

One line file operations in scala and Java. Here writes line with enter. Has also read and exists method. Used imports: import java.nio.cha

One line file operations in scala and Java. Here writes line with enter. Has also read and exists method.

Used imports: import java.nio.charset.StandardCharsets import java.nio.file.{StandardOpenOption, Files, Paths} import scala.collection.JavaConverters._

new PrintWriter(filePath) {
      list.foreach(obj => write(objToLine(obj)))
      close
    }
scala.io.Source.fromFile("test.dat").mkString // .getLines()
Files.write(Paths.get(stateFilePath), (json + '\n').getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND)