For example i want that the


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

how can I do it?

Recommended Answers

All 6 Replies

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

Because the System.out is type of PrintStream.

This will behave exactly like the System.out.println

PrintStream print = new PrintStream(System.out);

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.....

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...

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?

> 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.

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.out.println("text is visible again....");
commented: Bruh thank you so much, saved my courswork +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.