Java examples for java.lang:String Unicode
ISO-8859-1 encoding and binary data preservation
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Arrays; /**/*from www.j av a 2 s .c o m*/ * See <a href= * "http://stackoverflow.com/questions/15925458/iso-8859-1-encoding-and-binary-data-preservation" * >ISO-8859-1 encoding and binary data preservation</a> */ public class Main { private static final Charset CHARSET_ENCODING = StandardCharsets.ISO_8859_1; public static void main(String[] args) throws Exception { byte[] b = new byte[256]; for (int i = 0; i < b.length; i++) { b[i] = (byte) i; } String s = new String(b, CHARSET_ENCODING); byte[] b2 = s.getBytes(CHARSET_ENCODING); System.out.println("Are the bytes equal: " + Arrays.equals(b, b2)); } }