本帖最后由 Super_Class 于 2013-6-20 23:53 编辑
- <P>import java.io.*;
- import java.util.*;
- class Demo
- {
- public static void main(String[] args) throws IOException
- {
- OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("111.txt"),"GBK");
- InputStreamReader isr = new InputStreamReader(new FileInputStream("111.txt"),"GBK");
- osw.write("你好");
- osw.flush();
-
- System.out.println(isr.read()); //打印结果是20320
- osw.close();
- isr.close();
- }
- }</P>
- <P>我很疑惑一点:isr.read()方法是怎样将字符 "你" 字转成int型数据的,"你"字分两个字节,第一个字节是11000100( -60 ), 第二个字节是11100011(-29),这俩字节放一块就是11000100 11100011,这个二进制位提升成int型:00000000 0000000 11000100 11100011 转成十进制也应该是50403,为何打印出来的结果却是20320,这是怎么得来的???
- </P>
复制代码 |