In Java, how can I find the name of the stream which is passed as an argument, provided the given stream is either System.err or System.out?
public String getStreamName(OutputStream arg0) {
String streamName = ????;
return "This is stream: " + streamName;
}
should return something like:
This is stream: System.err
I’ve tried arg0.toString(), but that doesn’t seem useful, as the name returned is something like java.io.PrintStream@71cb25 and changes with each run. If the name was fixed, I could just compare it with the known names for stdout and stderr.
Try this: