File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How to avoid System.out.println() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to avoid System.out.println() " Watch "How to avoid System.out.println() " New topic

How to avoid System.out.println()

Girish K Gupta

Joined: Mar 14, 2007
Posts: 19

Hi All

I have a Java class file which has some System.out.prinltn() calls.
I want these SOPs should not be printed when I run the class (I am not supposed to modify the source .java file).

Please help me out.

PS: I don't know if this problem was discussed before on the forum, I tried searching but i didn't get any relevant thread.


Girish K Gupta
SCJP 1.5 - 87%, SCWCD 1.5 - 92%
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 692
Not modify the source?
Can you call/start the program in question from another program? If so, in the calling program you can change the value of System.out (setOut()) to be a NOP method before calling the program you can't modify.
Girish K Gupta

Joined: Mar 14, 2007
Posts: 19

Thanks Norm, I will try your suggestion.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
That's a weakness in the Java code, and obviously should be changed there.

Barring that, it depends on how you invoke the java application.

In most environments there are mechanisms for redirecting stdout and stderr to different places. (nowhere being one possibility)

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
subject: How to avoid System.out.println()
It's not a secret anymore!