Java 默认编码的字节数组到ISO-8859-1编码的字节数组
我有一个具有默认编码的字节数组。Java 默认编码的字节数组到ISO-8859-1编码的字节数组,java,encoding,bytearray,Java,Encoding,Bytearray,我有一个具有默认编码的字节数组。 我想将该字节数组更改为“ISO-8859-1”编码的字节数组。 如何做到这一点。。? 请帮帮我 byte[] isoBytes = new String(curBytes).getBytes("ISO-8859-1"); 但是,请注意,如果默认编码已经“丢失”了一些字符,则无法通过这种方式恢复这些字符。好的,因此您可以使用默认平台编码将字符串转换为字节数组(无论是什么)。您要使用ISO-8859-1将此字符串转换为字节数组 String str = new S
我想将该字节数组更改为
“ISO-8859-1”
编码的字节数组。如何做到这一点。。? 请帮帮我
byte[] isoBytes = new String(curBytes).getBytes("ISO-8859-1");
但是,请注意,如果默认编码已经“丢失”了一些字符,则无法通过这种方式恢复这些字符。好的,因此您可以使用默认平台编码将字符串转换为字节数组(无论是什么)。您要使用ISO-8859-1将此字符串转换为字节数组
String str = new String(currentByteArray);
byte[] newByteArray = str.getBytes("ISO-8859-1");
因此,第一步是将字节数组转换为字符串:
String s = new String(bytes); // default encoding used here
然后将其转换回字节数组:
byte[] iso88591Bytes = s.getBytes("ISO-8859-1");