Is there a Null OutputStream in Java? Is there a Null OutputStream in Java? java java

Is there a Null OutputStream in Java?


/**Writes to nowhere*/public class NullOutputStream extends OutputStream {  @Override  public void write(int b) throws IOException {  }}


Java doesn't it would seem but Apache Commons IO does. Take a look at the following:

https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/output/NullOutputStream.html

Hope that helps.


It's not mentioned yet, so I'll also add Guava's ByteStreams.nullOutputStream(), as some might prefer Guava over Apache Commons IO or already have it in their project.

Note: If you use an older version of Guava (from 1.0 to 13.0), you want to use com.google.io.NullOutputStream.