다음은 Linux 컴퓨터에서는 작동하지 않습니다.CharsetDecoder가 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 특유의 것이지만, 리눅스가 당신의 현재 디렉토리에 이런 복잡한 이름으로 파일을 생성 할 수 있다고 확신합니다. – andri
예외가 발생하지 않습니다. 파일을 생성하고'msgBody'의 복호화 된 문자열 대신'msgBody' 변수와 같은 것을 씁니다. –