Re: File /dev/null in Java ?
Oliver Wong writes:
J?rgen Gerstacker wrote:
is there a garbage file in Java like /dev/null in UNIX?
I want temporarily throw away System.out outputs.
....
Did you try this?
System.setOut(null);
I believe I did that a long time ago, and it seemed to work
(silenced the output, didn't throw null pointer exceptions).
The main problem I would have with that is that the docs do not say
anything about it - I just looked up System.setOut(PrintStream) for
Java 1.5.0 again.
A lesser problem is that when I tried it, it sure threw the exception:
[510] cat Roska.java
class Roska { public static void main(String [] args) {
System.setOut(null);
System.out.println("Hello?");
}}
[511] javac Roska.java
[512] java -cp . Roska
Exception in thread "main" java.lang.NullPointerException
at Roska.main(Roska.java:3)
This is from version 1.4.0; they haven't updated for a while.
Maybe you did it in a program that does not use System.out? The
exception is not from setOut() but from println() after that.