有没有办法改变 String(byte[]) 构造函数使用的编码?
在我自己的代码中,我使用 String(byte[],String) 来指定编码,但我使用的是无法更改的外部库。
String src = "with accents: é à";
byte[] bytes = src.getBytes("UTF-8");
System.out.println("UTF-8 decoded: "+new String(bytes,"UTF-8"));
System.out.println("Default decoded: "+new String(bytes));
输出是:
UTF-8 解码:带重音符号:é à 默认解码:带重音符号:é Ã
我尝试更改系统属性file.encoding
,但它不起作用。