Skip to content

Instantly share code, notes, and snippets.

@AnnaBoro
Created February 28, 2016 18:47
Show Gist options
  • Save AnnaBoro/096703c6ce12a2b6ac02 to your computer and use it in GitHub Desktop.
Save AnnaBoro/096703c6ce12a2b6ac02 to your computer and use it in GitHub Desktop.
system.out to file
package lesson8.chars;
import java.io.*;
public class DemoSystemOut {
public static void main(String[] args) {
try (OutputStream outputStream = new FileOutputStream(new File("system.out.txt"));
PrintStream printOut = new PrintStream(outputStream)) {
System.setOut(printOut);
System.out.println("Hello, world!");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment