Is there a Null OutputStream in Java?

Brandon Yarbrough picture Brandon Yarbrough · Mar 28, 2009 · Viewed 38.5k times · Source

I need to specify an OutputStream for an API I'm using, but I don't actually have a need for the output. Does Java have an OutputStream equivalent to > /dev/null?

Answer

McDowell picture McDowell · Mar 28, 2009
/**Writes to nowhere*/
public class NullOutputStream extends OutputStream {
  @Override
  public void write(int b) throws IOException {
  }
}