nutim
nutim

Reputation: 167

scala 2.11: how do I redirect console output to file

Console.setOut(printStream) method is deprecated in scala 2.11. Is there any other alternatives for this now? How do I redirect console output to file?

Upvotes: 1

Views: 2977

Answers (1)

Jeffrey Chung
Jeffrey Chung

Reputation: 19527

As the deprecation note in the Scaladoc states, use Console.withOut, which takes an OutputStream:

import java.io.{File, FileOutputStream}

val fos = new FileOutputStream(new File("/path/to/file.txt"))
Console.withOut(fos) { println("print this to the file") }

Upvotes: 3

Related Questions