String.getBytes(charset) has errors for EBCDIC-charset

冷暖自知 提交于 2019-12-04 11:49:08

When you call

data.getBytes(ebcdic)

You are encoding the text in data into EBCDIC bytes. Then you create a string from these bytes as if they stood for some string in the default character encoding for your system: this causes breakage because the bytes don't have to encode valid text in any other encoding than EBCDIC.

To fix this, keep bytes as bytes:

byte[] result= data.getBytes(ebcdic);
System.out.printf("EBCDIC: %s\n",asHex(result));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!