Alternate between writing to text file and console in JAVA
<p>I want to write to a text file. Then, I want to continue printing to the console.</p>

<p>I am able to successfully output to the text file. However, after closing the PrintStream created to write to the text file, I am unable to print to the console. In the code below, for instance, the text file has the output from the method called "permutation" followed by the phrase "Test before close". However, the phrase "Test after close" is printed to neither the text file nor the console. Thanks for any advice!!</p>

<pre><code>public static void main(String[] args) throws FileNotFoundException {
    PrintStream out2 = new PrintStream(new FileOutputStream("output.txt"));
    System.setOut(out2);
    permutation("1234");
    System.out.println("Test before close");
    out2.close();
    System.out.println("Test after close");
}
</code></pre>
