1,105,352 Community Members

How to disabple the standart output to be dsiplayed... - disable System.out.println()

Member Avatar
vedmack
Junior Poster in Training
59 posts since Feb 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

For example i want that the

System.out.println("blablabla");

wont be displayed on the screen of the console....


how can I do it?

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
0
 

Where do want it to be displayed because I don't think that it can be done.

I would suggest you look at the API for
PrintStream

Because the System.out is type of PrintStream.

This will behave exactly like the System.out.println

PrintStream print = new PrintStream(System.out);
        print.println("aaaaa");
Member Avatar
vedmack
Junior Poster in Training
59 posts since Feb 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

the print outs are beeing called from some API's calling.... so i want to disable/ re route the standart print out before calling the API and enable it after finished using the API.....

Member Avatar
peter_budo
Code tags enforcer
7,935 posts since Dec 2004
Reputation Points: 2,502 [?]
Q&As Helped to Solve: 1,028 [?]
Skill Endorsements: 66 [?]
Moderator
Featured
 
0
 

I think you do not understand what you want to do. System.out.println() are system calls you placed there for some reason by programmer (in this case by you, and you may not complitelly understand them). If you want to threat data handled by system calls differently you have to tell us if you wish to store them (file read/writing), show them to user in different form (GUI or just simple dialogue po-ups) or you do not wish to see any warning messages from your system in console.
So please explain your self as above doesn't make any sense...

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
0
 

Peter is right. If you don't want the message to printed at the console, don't call that method.

And as I asked in my post:

Where do want it to be displayed?

Member Avatar
~s.o.s~
Failure as a human
10,399 posts since Jun 2006
Reputation Points: 2,496 [?]
Q&As Helped to Solve: 992 [?]
Skill Endorsements: 72 [?]
Administrator
Featured
 
0
 

> how can I do it?

By reassigning the out member of the System class using setOut(PrintStream) .

System.setOut(new PrintStream(new OutputStream() {
  public void write(int b) {
    // NO-OP
  }
}));

Or simply redirect the output to a file or /dev/null [unix] when running the Java command:

java your.pkg.your.class > log.txt
java your.pkg.your.class > /dev/null

The kind of functionality you are seeking i.e. conditional enable/disable of print statements and redirection to a different source are screaming out for the want of a logger library. Look into Log4j for more details.

Member Avatar
vedmack
Junior Poster in Training
59 posts since Feb 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks ~s.o.s~

U pointed me with the solution! :)

here what i did:

System.out.println("text is visible");
		PrintStream printStreamOriginal=System.out;


                System.setOut(new PrintStream(new OutputStream(){
			public void write(int b) {
			}
		}));
		System.out.println("this text will be lost");



                System.setOut(printStreamOriginal);
		System.out.println("text is visible again....");
Question Answered as of 5 Years Ago by javaAddict, peter_budo and ~s.o.s~
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article