问下大家为什么我输出 "郑泉" 这个字符串到文本里会出现乱码,其他的就不会呢
问下编码保存格式要求是ANSI。到底 "郑泉" 这是特殊字符,还是? 请教大家。附上以下代码:
  
   InputStream is = new ByteArrayInputStream("郑泉".getBytes());
OutputStream os;
 
os = new FileOutputStream("d:\\qq.txt");
byte[] buffer = new byte[2048];
int length = 0;
while (-1 != (length = is.read(buffer, 0, buffer.length))) {
os.write(buffer, 0, length);
}
is.close();
os.close();

解决方案 »

  1.   

    IO包那么多可以用的类,选ByteArrayInputStream干什么。
      

  2.   

    getBytes()加个编码格式  getBytes("utf8")试下
      

  3.   

    InputStream is = new ByteArrayInputStream(new String("郑泉".getBytes("GBK"),"ANSI"));
    试试
      

  4.   

    InputStream is = new ByteArrayInputStream(new String("郑泉".getBytes("GBK"),"ANSI"));
    试试
      

  5.   

    第一行改成 
    InputStream is = new ByteArrayInputStream("郑泉".getBytes("UTF-8"));