字节流是由字节组成的,字符流是由字符组成的. Java里字符由两个字节组成.

解决方案 »

  1.   

    楼上的都说清楚了byte char
      

  2.   

    我用DataOutputStream流来写一个data.txt的文件时
    File aFile=new File("c:\\data.txt");
    String s=new String("Garbage in, garbagae out");
    DataOutputStream myStream=new DataOutputStream(
                                           new FileOutputStream(aFile));
    myStream.writeChars(s);编译写入之后,打开data,txt之中的文本却是G a r b a g e  i n ,  g a r b a g e  o u t
    为什么会多了这么多的空格?
      

  3.   

    myStream.write(s.getBytes());
    就没问题了
    你用writeChars当然出现空格了
      

  4.   

    一个字符两个字节,
    用s.getBytes();与原先s有什么不同?
      

  5.   

    Java中的字符是Unicode的,由两个字节组成。