1

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?

overexchange
  • 15,768
  • 30
  • 152
  • 347
  • 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`. – Tim Biegeleisen Oct 26 '17 at 11:30
  • Please see https://docs.oracle.com/javase/7/docs/api/java/lang/System.html – vikingsteve Oct 26 '17 at 11:30
  • 1
    Simply inspect what objects ``System.in`` and ``System.out`` are during runtime... – f1sh Oct 26 '17 at 11:30
  • `InputStreamReader` is to read standard input stream – Lokesh Pandey Oct 26 '17 at 11:31
  • 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. – vikingsteve Oct 26 '17 at 11:32
  • Your Wikipedia link tells you that it's System.in/out/err and includes links to [the docs](https://docs.oracle.com/javase/9/docs/api/java/lang/System.html) which tells you the types of those variables. – Bernhard Barker Oct 26 '17 at 11:33
  • voting to remove the duplicate tag – Lokesh Pandey Oct 26 '17 at 11:33
  • 2
    I removed the duplicate quesiton and replaced it with another. Does it look good now? – vikingsteve Oct 26 '17 at 11:33
  • @vikingsteve I like the look of beige, even if I'm not the doing it :-) ... maybe not an exact duplicate, but the issue is that the OP should not be using the classes he mentioned, he should use classes designed to work with `System.in` and `System.out`. – Tim Biegeleisen Oct 26 '17 at 11:37
  • @TimBiegeleisen if you feel its better to remove the duplicate and answer the question, that's fine too. Otherwise the OP is specifically looking for *types* and the short answer is: `PrintStream` and `InputStream` – vikingsteve Oct 26 '17 at 11:38
  • @vikingsteve So, according to your referred duplicate, `FileOutputStream` is working with `stdout`- `FileDescriptor`, `FileInputStream` works with `stdin`- `FileDescriptor`. What about `stderr`? Of course `PrintStream` is wrapping it via `BufferedInputStream` & `BufferedOutputStream` – overexchange Oct 26 '17 at 11:39
  • Imagining a stream is always a mystery for java programmer except saying that it is implementation detail. Is java internally relying on C `FILE *` stream? – overexchange Oct 26 '17 at 11:46
  • @vikingsteve `InputStream` is an abstract class. How would you talk to `stdin` & `stderr`? You are using lot of energy in finding duplicates. – overexchange Oct 26 '17 at 11:53
  • Ok I will removed the duplicate and you can answer it if you have time. There was a different dubplicate posted by Tim, I changed it to a better one. – vikingsteve Oct 26 '17 at 11:56
  • Your understanding is incorrect. `FILE *` has nothing to do with it. Unclear what you're asking. – user207421 Oct 26 '17 at 12:00
  • @EJP Stream is a sequential buffer created on opening a resource. Contents of a resource are copied to that buffer. This buffer is the source that is read/write from/to. `FILE *` is a stream in C world. Does java rely on `FILE *`? What is that unclear for you that so many users here are talking about? – overexchange Oct 26 '17 at 12:13

1 Answers1

2

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.

vikingsteve
  • 38,481
  • 23
  • 112
  • 156
  • 1
    `FileInputStream(FileDescriptor fdObj)` where `fdObj` can be 0 for `stdin`. `FileOutputStream(FileDescriptor fdObj)` where `fdObj` can be 1 for `stdout` and 2 for `stderr`. – overexchange Oct 26 '17 at 12:01
  • 1
    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. – Peter Lawrey Oct 27 '17 at 08:35