美文网首页
Java Charset和字符串

Java Charset和字符串

作者: __Liu__ | 来源:发表于2017-09-14 16:21 被阅读0次
  1. Java里面的String类型,在内存中,没有io之前,都是unicode。
  2. Charset常见的几个ISO-8859-1, GBK, UTF-8,都是把unicode按照特定的规范转换成字符。其中utf-8涵盖unicode最广泛

常见的例子:

  1. 一个文件以utf-8的charset存储,你用gbk读取了,怎么还原文件的内容
    将读取的char[](String this.value)按照GBK encode后写出来,再按照UTF-8 decode后写回到char[](String this.value)
  String errStr = "gbkCharSetStr";
  new String(errStr.getBytes("GBK"),"UTF-8");
  1. 一个以gbk存储的文件,怎么样保存为utf-8的charset文件
  InputStreamReader isr = new InputStreamReader(new FileInputStream(gbkFileName),"GBK");
  OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(utf8FileName),"UTF-8");

相关文章

网友评论

      本文标题:Java Charset和字符串

      本文链接:https://www.haomeiwen.com/subject/fepdsxtx.html