Redirecting stdin and stdout in scala

后端 未结 2 517
一生所求
一生所求 2021-01-24 13:05

How can I redirect STDIN and STDOUT to files?

In C, this would be done like so:

freopen(\"file.in\",\"r\",stdin);

I am looking for some

2条回答
  •  被撕碎了的回忆
    2021-01-24 13:48

    You can do it using the Java System api. The code is nearly identical for Java and Scala:

    System.setIn(new FileInputStream("file.in"))
    System.setOut(new PrintStream(new FileOutputStream("file.out")))
    

提交回复
热议问题