如何改回标准输出控制台?

How to change back to standard output console?

我尝试将 PrintStream 打印到文本文件以将一堆输出写入文件。

但在创建文件后,我试图切换回标准输出以继续其他进程,但我不知道是否要进行该切换。好像我必须 setOut 到标准控制台,但我该怎么做?

下面是我用来输出到文本文件的代码。有什么想法吗?

PrintStream out = new PrintStream(fistr);
System.setOut(out);

谢谢。

为什么修改前不保存,方便返回呢?

PrintStream standard = System.out;
PrintStream out = new PrintStream(fistr);
System.setOut(out);
/*
 some other stuff
*/
System.setOut(standard);