InputOutputDemoStandardInputOutput.java Source code

Java tutorial

Introduction

Here is the source code for InputOutputDemoStandardInputOutput.java

Source

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class InputOutputDemoStandardInputOutput {

    public static void main(String[] a) throws Exception {

        //Write characters to standard output and standard error:
        System.out.println("std output");
        System.err.println("std error");
        //Read characters from standard input (the keyboard):
        System.out.print("Type some characters and press Enter: ");
        BufferedReader bisr = new BufferedReader(new InputStreamReader(System.in));
        String response = bisr.readLine();
        System.out.println("You typed: '" + response + "'");
        //Read a byte from standard input (the keyboard):
        System.out.print("Type one character and press Enter: ");
        byte b = (byte) System.in.read();
        System.out.println("First byte of your input is: " + b);
    }
}