为什么用FileInputStream,FileOutputStream读写中文可以,不是只有Reader,Writer才能处理字符吗?
它是怎么将读到的字节转化成了字符?

解决方案 »

  1.   

    java.io.*;中介绍是:
     java.io.Reader ->java.io.InputstreamReader ->java.io.FileReader(java.io.FileWriter)
      

  2.   

    FileInputStream,FileOutputStream应该是一个字节一读一写吧,读写中文有时候会出现乱码吧!
    不知道说的对不对!
      

  3.   

    有没有人详细解释一下?
    如果它们可以作用于中文字符,那为什么还要FileReader/FileWriter?
      

  4.   

    public static void main(String[] args) throws Exception {
    FileInputStream in = new FileInputStream("c:\\aa.txt");
    int i = 0;
    while ((i = in.read()) != -1) {
    System.out.println((char)i);
    }
    //==========================================
    byte[] b = new byte[10];
    i = 0;
    while ((i = in.read(b)) != -1) {
    System.out.println(new String(b, "gb2312"));
    }
    in.close();
    }上面两种方法你用哪一种呢?
    第一种肯定会出现乱码的。因为每次读一个字节.第二种当汉字前单字节为2的倍数时不会出现乱码.
      

  5.   

    public String getStr(String str) 
    {
         try {
               String temp = str;
               byte[] temp_bt = temp.getBytes("ISO8859-1");
               String temp_p = new String(temp_bt);
               return temp_p;
             }catch (Exception e) 
             {
               System.out.println(e.getMessage());
             }
          return "null";
        }把乱码转中成中文
      

  6.   

    大虾门有点偏题了,我想知道为什么用FileInputStream/FileOutputStream可以读写中文?