platform-independent /dev/null output sink for Java(独立于平台的 Java 的/dev/null 输出接收器)
问题描述
除了匿名类 (new OutputStream() { ... }
) 之外,任何人都可以提出与 new FileOutputStream("/dev/null") 等价的道德规范
也适用于 Windows?
Other than an anonymous class (new OutputStream() { ... }
), can anyone suggest a moral equivalent of new FileOutputStream("/dev/null")
that also works on Windows?
万一有人想知道这是做什么用的?"
In case someone's wondering 'what's this for?'
我有一个程序可以对文件进行一致性分析.它有一个详细"选项.当详细选项打开时,我想看到很多输出.该程序并不着急,它是一个工具,因此与其编写所有这些额外的 if
语句来测试我是否需要输出,我只想在不需要时将其写入位桶.
I have a program that does a consistency analysis on a file. It has a 'verbose' option. When the verbose option is on, I want to see a lot of output. The program is not in a hurry, it's a tool, so instead of writing all those extra if
statements to test if I want the output, I just want to write it to the bit-bucket when not desired.
推荐答案
您可以使用来自 apache commons 的 NullOutputStreamhttps://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/output/NullOutputStream.html
You can use NullOutputStream from apache commons https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/output/NullOutputStream.html
或者只是实现自己的
package mypackage;
import java.io.OutputStream;
import java.io.IOException;
public class NullOutputStream extends OutputStream {
public void write(int i) throws IOException {
//do nothing
}
}
这篇关于独立于平台的 Java 的/dev/null 输出接收器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:独立于平台的 Java 的/dev/null 输出接收器


基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01