Read user input char value from console in Java

Description

The following code shows how to read user input char value from console.

Example


/*ww  w.j  a  v a  2s .  c  om*/
import java.io.IOException;

public class Main {

  public static void main(String[] args) {

    try {
      char c = (char) System.in.read();
      while (c != '\r') {
        System.out.println(c);
        c = (char) System.in.read();
      }
    } catch (IOException e) {
    }

  }

}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip