Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/java/io/InputStreamReader/InputStreamReader.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/java/io/InputStreamReader/InputStreamReader.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/io/InputStreamReader/InputStreamReader.html on line 2
標準入力から1文字読み込む | Java | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/io/InputStreamReader/InputStreamReader.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/io/InputStreamReader/InputStreamReader.html on line 17
標準入力から1文字読み込む
標準入力はSystem.inです。このストリームから1文字読み込むにはjava.io.InputStreamReaderクラスを使用します。
1文字読み込むにはInputStreamReaderクラスのread()メソッドを使用します。

サンプル
以下、標準入力からyかnを押した時の例です。
yと入力するとyと表示され、nと入力するとnと表示されます。

import java.io.InputStreamReader;

public class Test{
    public static void main(String[] args){
        InputStreamReader reader=new InputStreamReader(System.in);
        try{
            System.out.println("y/n?");
            int key = reader.read();
            if(key == 'y' || key == 'Y'){
                System.out.println((char)key);
            }else{
                System.out.println((char)key);
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
yを押した時の出力結果は以下のようになります。

y/n?
y

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/io/InputStreamReader/InputStreamReader.html on line 93

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/io/InputStreamReader/InputStreamReader.html on line 93

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/io/InputStreamReader/InputStreamReader.html on line 102

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/io/InputStreamReader/InputStreamReader.html on line 102