Re: File /dev/null in Java ?
"Jussi Piitulainen" <jpiitula@ling.helsinki.fi> wrote in message
news:qot64d097x9.fsf@venus.ling.helsinki.fi...
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)
I tried it again in 1.6, and it threw the NPE also. I guess I
misremembered what I had done.
- Oliver