String.getBytes (charset)를 통한 EBCDIC 로의 문자열 변환은 적어도 하나의 잘못된 결과를 제공합니다. 문자 "a"는 0x3f가되지만 0x81이어야합니다.String.getBytes (charset)는 EBCDIC- 문자 세트에 대해 오류가 있습니다.
public static void convert() throws UnsupportedEncodingException {
String data="abcABC";
String ebcdic = "IBM-1047";
String ascii = "ISO-8859-1";
System.out.printf("Charset %s is supported: %s\n", ebcdic, Charset.isSupported(ebcdic));
String result= new String(data.getBytes(ebcdic));
System.out.printf("EBCDIC: %s\n",asHex(result.getBytes()));
System.out.printf("Charset %s is supported: %s\n", ascii, Charset.isSupported(ascii));
result= new String(data.getBytes(ascii));
System.out.printf("ASCII: %s\n",asHex(result.getBytes()));
}
public static String asHex(byte[] buf) {
char[] HEX_CHARS = "abcdef".toCharArray();
char[] chars = new char[2 * buf.length];
for (int i = 0; i < buf.length; ++i)
{
chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4];
chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F];
}
return new String(chars);
}
결과 인도 표준시 :
- 캐릭터 세트 IBM-1047 지원 : 사실
- EBCDIC : 3f8283c1c2c3는
- 캐릭터 세트 ISO-8859-1이 지원됩니다 사실
- ASCII : 616,263,414,243
내가 할 수있는 조치는 무엇입니까? 당신은 당신은 EBCDIC 바이트에 데이터의 텍스트를 인코딩하는
data.getBytes(ebcdic)
전화
적절한 언어 태그를 추가하십시오. –