Java - IO - Standard Streams

> Procedural Languages > Java > Java - IO (Input/Output) - (File System|File|Console)

1 - About

3 - Management

3.1 - Manipulation

For historical reasons, Standard Streams are byte streams and not character streams

  • System.out and System.err are defined as PrintStream objects. PrintStream is technically a byte stream but emulate many of the features of character streams (println,…)
  • System.in is a byte stream with no character stream features. To use Standard Input as a character stream, wrap System.in in InputStreamReader.
InputStreamReader in = new InputStreamReader(System.in);
Advertising

3.2 - Reassignment

3.3 - Read a pipe redirection in the main class

int counter = 0;
int input;			}
while((input=System.in.read())!=-1){
	counter++;
	System.out.println(counter+ " - "+input+" char ("+(char) input+")");
}

3.4 - Printing on the same line

Whatever ... \r

The \r carriage return move the cursor back to the beginning of the line.

System.out.print() (not System.out.println() that adds a end of line)

lang/java/io/standard_stream.txt · Last modified: 2017/07/02 16:54 by gerardnico