我有一个属性文件,其中包含亚洲语言的翻译,我认为该文件保存为ISO-8859-1格式。我试图将它们转换为UTF-8格式。所以è¦å:
应该等于警告:
我已经尝试了这个网站和其他一些网站上列出的几种方法,但是都没有成功。
byte[] isoBytes = line.getBytes("ISO-8859-1");
byte[] utf8 = new String(isoBytes, "ISO-8859-1").getBytes("UTF-8");
CharBuffer charBuf = null;
Charset isocharset = Charset.forName("iso-8859-1");
CharsetDecoder isoDecoder = Charset.forName("iso-8859-1").newDecoder();
CharsetDecoder utf8Decoder = Charset.forName("UTF-8").newDecoder();
byte sByte[] = line.getBytes("iso-8859-1");
charBuf = utf8Decoder.decode(isoBuf);
最简单的方法是将è¦å:
转换为警告:
,谢谢Rich。@Pshemo提供了我要找的答案。
byte[] isoBytes = line.getBytes("ISO-8859-1");
System.out.println(new String(isoBytes, "UTF-8"));
谢谢大家的帮助。
byte[] isoBytes = line.getBytes("ISO-8859-1"); System.out.println(new String(isoBytes, "UTF-8"));
看起来运行良好。 - Pshemo