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 输出接收器


基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01