以下不适用于linux机器。
Charset charset = Charset.forName("UTF-8");
CharsetDecoder decoder = charset.newDecoder();
try {
FileOutputStream fo = new FileOutputStream("hi.txt");
PrintStream ps = new PrintStream(fo);
String msgBody = "ΣYMMETOXH";
ps.println(decoder.decode(ByteBuffer.wrap(decoder.decode(ByteBuffer.wrap(msgBody.getBytes())).toString().getBytes())));
ps.close();
fo.close();
} catch (CharacterCodingException e) {
e.printStackTrace();
}
此代码适用于 Windows。可能是什么问题?在 linux 机器上解码器不解码字符串。