public static OutputStream nullOutputStream() {
return new OutputStream() {
private volatile boolean closed;
private void ensureOpen() throws IOException {
if (closed) {
throw new IOException("Stream closed");
}
}
@Override
public void write(int b) throws IOException {
ensureOpen();
}
@Override
public void write(byte b[], int off, int len) throws IOException {
Objects.checkFromIndexSize(off, len, b.length);
ensureOpen();
}
@Override
public void close() {
closed = true;
}老师close方法里没有回收资源啊只是返回true,真的回收在哪里啊?
};
}
展开
作者回复:
不确定你这个代码哪儿来的,但是看方法名的话,这是nullOutputStream,应该是某些特殊的情况下使用的。