Created
February 28, 2016 18:47
-
-
Save AnnaBoro/096703c6ce12a2b6ac02 to your computer and use it in GitHub Desktop.
system.out to file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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