
Untitled
By: a guest on
Apr 25th, 2012 | syntax:
None | size: 0.80 KB | hits: 11 | expires: Never
java charset decode issue
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:ㄅ