char ch=(char)System.in.read();
用这条语句时注意读取的char型数据;

解决方案 »

  1.   

    try{String str = (String)System.in.read();}
    catch(Exception se){System.out.println(se);}
      

  2.   

    byte[] buffer =new byte[2056];
    try{
    while(true){
    int bytes=System.in.read(buffer,0,2056);
    String str=new String(buffer,0,bytes);
    System.out.println(str);
    str=str.substring(0,3);
    if(str.equals("end")){
    System.out.println("输入结束!退出");
    break;
    }
    }
    }
    catch(Exception e){
       System.out.println(e.toString());
    }
      

  3.   

    BufferedInputStream istream = new BufferedInputStream(System.in);
    istream.readLine() // 读取一行数据。Java 中读取数据只能在回车后能才开始读取,不可能像 C 里用 getch 那样按一个键就能读一个字符。
      

  4.   

    public staitc void input()
    {
       BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
       try{
                s=br.readLine();
          }
       catch(IOException){}
    }