2
나는 문자 ·
사용하여 캐릭터에게 자바에서 GB2312를 해독하기 위해 노력하고있어이자바 캐릭터 세트 디코드 문제
GB2312에 포함 된이 문자는 위치 코드는 a1a4
check here
코드 :
public static void main(String[] _args) throws Exception {
String str="a1a4:· a5f6:ヶ a8c5:ㄅ";
ByteBuffer bf=readToByteBuffer(new ByteArrayInputStream(str.getBytes()));
System.out.println(Charset.forName("GB2312").decode(bf).toString());
}
private static final int bufferSize = 0x20000;
static ByteBuffer readToByteBuffer(InputStream inStream) throws IOException {
byte[] buffer = new byte[bufferSize];
ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize);
int read;
while (true) {
read = inStream.read(buffer);
if (read == -1)
break;
outStream.write(buffer, 0, read);
}
ByteBuffer byteData = ByteBuffer.wrap(outStream.toByteArray());
return byteData;
}
출력 결과 위 코드는
a1a4:? a5f6:ヶ a8c5:ㄅ
내가 왜 a1a4
를 디코딩 할 수 이해하지?
'IO.string2InputStream (d)'도 GB2312 charset을 사용하여 쓰는 것으로 가정합니다. 버퍼의 바이트가 올바른지 확인 했습니까? –
@RussellZahniser 죄송합니다. 내 질문을 편집했습니다. – Koerr
아마도'str.getBytes ("GB2312")'를하고 싶을 것입니다. 기본값 인 UTF8을 사용하고있을 것입니다. 그러나 나는 seh가 그것이 인코딩 문제 라기보다 인물 이슈라는 것이 옳다고 생각한다. –