Redirect standard output : Redirect « File Input Output « Java

Redirect standard output


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");


Related examples in the same category

1.Redirect standard error
2.Redirecting Standard Output, and Error
3.Replace standard output and error with a print stream, output to both the console and to a file.
4.Standard Err and Output Windows
5.Redirect standard output to a file