I'm using a java library (jar file). The author of the file put in a bunch of System.out.print
and System.out.println
s. Is there any way to hide these messages for a particular object?
*EDIT: It looks like the jar file seems to be creating a bunch of threads and each thread has it's own System.out.println's...
System. out. println does not print to the console, it prints to the standard output stream ( System. out is Java's name of the standard output stream).
Java System. out. println() is used to print an argument that is passed to it.
It is used when you want the result in two separate lines. It is called with "out" object. If we want the result in two separate lines, then we should use the println() method. It is also an overloaded method of PrintStream class.
The println() method of this accepts any a value ( of any Java valid type), prints it and terminates the line. By default, console (screen) is the standard output Stream (System.in) in Java and, whenever we pass any String value to System. out. prinln() method, it prints the given String on the console.
Change original PrintStream with a Dummy one which does nothing on it's write()
method.
Don't forget to replace original PrintStream when you finished.
System.out.println("NOW YOU CAN SEE ME");
PrintStream originalStream = System.out;
PrintStream dummyStream = new PrintStream(new OutputStream(){
public void write(int b) {
// NO-OP
}
});
System.setOut(dummyStream);
System.out.println("NOW YOU CAN NOT");
System.setOut(originalStream);
System.out.println("NOW YOU CAN SEE ME AGAIN");
System.setOut();
is probably what you're looking for
System.setOut(new PrintStream(new OutputStream() {
public void write(int b) {
// NO-OP
}
}));
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With