本文介绍了用于标准流的Java的InputStream / OutputStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是,字符流和字节流在C FILE * 流内部工作。





C world中的标准流 FILE * stdin FILE * stdout & FILE * stderr








和 api文档没有谈到 - stdin / stdout / stderr






InputStream的哪个子类 / OutputStream 专用于标准流?

解决方案

如果您查看源代码系统类,您可以看到以下类型:

  public final static PrintStream out = null; 
public final static PrintStream err = null;
public final static InputStream in = null;

即。 stdin和stderr的类型为 PrintStream ,stdin为 InputStream



当然,我们应该通过 System.out.println()和类似的操作来访问它们。



In与您在问题中显示的输入流 / OutputStream 的关系, PrintStream extends FilterOutputStream 扩展 OutputStream PrintStream 的主要目的是添加样式的有用函数 print() println ()依此类推。


My understanding is, character streams and byte streams work internally over C FILE * stream.

standard streams in C world are FILE * stdin, FILE *stdout & FILE *stderr


InputStream and OutputStream are providing subclasses for resources like file, pipe...

InputStream and OutputStream api documentation does not talk about standard streams- stdin/stdout/stderr.


Which subclass of InputStream/OutputStream dedicated for standard streams?

解决方案

If you look in the source for System class, you can see the following types:

public final static PrintStream out = null;
public final static PrintStream err = null;
public final static InputStream in = null;

i.e. stdin and stderr are of type PrintStream and stdin is InputStream.

Naturally, we should access them via System.out.println() and similar operations.

In relation to the Inputstream / OutputStream that you showed in your question, PrintStream extends FilterOutputStream which extends OutputStream. The main purpose of PrintStream is to add useful functions of the style print(), println() and so on.

这篇关于用于标准流的Java的InputStream / OutputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 00:02