2

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

enter image description here

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


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

enter image description here

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


Which subclass of InputStream/OutputStream dedicated for standard streams?

16
  • Feel free to remove this duplicate hammer, or add more duplicate links if you wish. We can easily use System.in and System.out as input and output streams to access stdin and stdout. Commented Oct 26, 2017 at 11:30
  • Please see docs.oracle.com/javase/7/docs/api/java/lang/System.html Commented Oct 26, 2017 at 11:30
  • 1
    Simply inspect what objects System.in and System.out are during runtime... Commented Oct 26, 2017 at 11:30
  • 1
    @TimBiegeleisen I dont think this is a duplicate of the question you linked. Seems that OP is asking the types of stdin, stderr, stdout in java. Not how to read from them. Commented Oct 26, 2017 at 11:32
  • 2
    I removed the duplicate quesiton and replaced it with another. Does it look good now? Commented Oct 26, 2017 at 11:33

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

FileInputStream(FileDescriptor fdObj) where fdObj can be 0 for stdin. FileOutputStream(FileDescriptor fdObj) where fdObj can be 1 for stdout and 2 for stderr.
System.out and System.err are PrintStream rather than InputStream for convenience and assumes you want to write text. Somewhat inconsistently, in is not a BufferedReader` or a Scanner which would have been useful. Instead we have Console class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.