App下載
首頁javastandard_streamJava I/O - 如何將標(biāo)準(zhǔn)輸出重定向到文件

Java I/O - 如何將標(biāo)準(zhǔn)輸出重定向到文件

我們想知道如何將標(biāo)準(zhǔn)輸出重定向到文件。
import java.io.FileOutputStream;
import java.io.PrintStream;

public class Main {
  public static void main(String[] args) throws Exception {
    System.setOut(new PrintStream(new FileOutputStream("system_out.txt")));
    System.out.println("sent to the file system_out.txt");
  }
}