import java.io.IOException;
import java.io.InputStreamReader;public class TestInputStreamReader{
public static void main(String args[])throws IOException{
    InputStreamReader isr=new InputStreamReader(System.in,"GBK");
                                         //"GBK"换成其他字符编码就是乱码
    int c=0;
    while((c=isr.read())!=13){
        System.out.print((char)c);
    }
}
}
现在好像有点似懂非懂的感觉,谁来说一下原理,让我彻底明白?谢谢

解决方案 »

  1.   

    从控制台台取一个字符 当一个字符的ascii值不为13就打印该字符
      

  2.   


      字符流读取,“GBK”才能使汉字读出来,utf-8等不能
      

  3.   

    计算机内部传送数据都是二进制的,也就是说,无论什么东西,都变成0和1来传递。
    字符串也一样。
    同样给你一组二进制的0和1,用不同的编码来解释它,得到的结果是不一样的。
    new InputStreamReader(System.in,"GBK");
    意思就是说,从System.in这个字节流得到字符流的时候,用GBK作为编码方式。
      

  4.   

    import java.io.IOException;
    import java.io.InputStreamReader;public class TestInputStreamReader{
            public static void main(String args[])throws IOException{
                InputStreamReader isr=new InputStreamReader(System.in,"GBK");
                                             //"GBK"换成其他字符编码就是乱码
                int c=0;
                while((c=isr.read())!=13){
                    System.out.print((char)c);
                }
               isr.close()  //这一步也很重要
            }
    }