我有一个带有重音字符的文件:ÇÍââÇÍ
我需要将它们更改为ISO-8859-15编码
编码:
String fileName = "C:/Users/User/AppData/Local/Temp/temp6893820181068878551.txt";
File file = new File(fileName);
FileInputStream fin = new FileInputStream(file);
FileChannel ch = fin.getChannel();
int size = (int) ch.size();
MappedByteBuffer buf = ch.map(FileChannel.MapMode.READ_ONLY, 0, size);
byte[] utf8bytes = new byte[size];
buf.get(utf8bytes);
System.out.println(new String(utf8bytes));
System.out.println();
System.out.println();
Charset utf8charset = Charset.forName("UTF-8");
Charset iso88591charset = Charset.forName("ISO-8859-15");
String string = new String ( utf8bytes, utf8charset );
System.out.println(string);
System.out.println();
System.out.println();
byte[] iso88591bytes = string.getBytes(iso88591charset);
for ( byte b : iso88591bytes )
System.out.printf("%02x ", b);
System.out.println();
System.out.println();
String string2 = new String ( iso88591bytes, iso88591charset );
System.out.println(string2);
但我得到输出:
ÇÍââÇÍ
??????
3f 3f 3f 3f 3f 3f
??????