This should do it for you:
import java.io.*;
/**
* Demonstrate reading characters from the console using
* the standard input from System.in wrapped with
* InputStreamReader.
**/
public class SingleCharIOApp
{
public static void main (String arg[]) {
char ch;
int tmp = 0;
// System.in std input stream already opened by default.
// Wrap in a new reader stream to obtain 16 bit capability.
InputStreamReader reader = new InputStreamReader (System.in);
// System.out std output stream already opened by default.
// Wrap in a new writer stream to obtain 16 bit capability.
OutputStreamWriter writer = new OutputStreamWriter (System.out);
try {
// Hit CTRL-Z on PC's to send EOF, CTRL-D on Unix.
// The EOF puts -1 = 0xFFFFFFFF into integer.
while (tmp != -1 ) {
// Read a single character from keyboard
tmp = reader.read ();
// A 1 byte character is returned in integer.
// Cast to char to get character in low 2 bytes.
ch = (char) tmp;
// If a symbol character with 2 byte unicode read in,
// the will see 4 hex output
writer.write ("echo " + ch
+ " whose code = "+ Integer.toString (tmp,16) + '\n');
// Need to flush the OutputStream buffer to get the
// characters sent to the screen.
writer.flush ();
}
}
catch (IOException e) {
System.out.println ("IO error:" + e );
}
} // main
} // class SingleCharIOApp