- Java里面的String类型,在内存中,没有io之前,都是unicode。
- Charset常见的几个ISO-8859-1, GBK, UTF-8,都是把unicode按照特定的规范转换成字符。其中utf-8涵盖unicode最广泛
常见的例子:
- 一个文件以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");
- 一个以gbk存储的文件,怎么样保存为utf-8的charset文件
InputStreamReader isr = new InputStreamReader(new FileInputStream(gbkFileName),"GBK");
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(utf8FileName),"UTF-8");