System.in.read()试过了,不行啊!还有办法吗?或者可以给我一个例子吗?

解决方案 »

  1.   

    //由用户输入字符串
       int b=-1;
        byte buffer[]=new byte[1024];
        b = System.in.read(buffer);
        String strInput = new String(buffer,0,b-2);
        System.in.close();    //将字符串转换为字符数组
        char[] charInput = strInput.toCharArray();
      

  2.   

    import java.io.*;
    class BRRead{
      public static void main(String arg[])
        throws IOException
       {
        char c;
        BufferedReader br=new
            BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter characters,'q' to quit.");
        //read characters
        do{
          c=(char)br.read();
          System.out.println(c) ;
        }while(c!='q');
      }
    }
      

  3.   

    最简单的使用System.in.read(byte[],int,int)就可以搞定,不过可能不能满足你的要求,象这样byte[] input=new byte[10];
    System.int.read(input,0,input.length);
    System.out.println(new String(input));如果你输入的字符串长度大于input的长度,那么后面的将被截掉
      

  4.   

    谢谢各位的帮助,采用的hehecafe的办法解决了问题,但是zhjjava对我也有帮助,由于原来问题给的分值就少,所以只能这样给分了