miércoles, 22 de agosto de 2012

Convertir string a byte[] en Java


Para convertir de string a Byte[] utilizamos el siguiente código Java:


String source = "0123456789";
byte[] byteArray = source.getBytes("UTF-16");

El mapeo entre las secuencias de dieciséis bits caracteres Unicode y secuencias de bytes puede ser de los siguientes tipos:


Charset
Description
US-ASCII Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set
ISO-8859-1   ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
UTF-8 Eight-bit UCS Transformation Format
UTF-16BE Sixteen-bit UCS Transformation Format, big-endian byte order
UTF-16LE Sixteen-bit UCS Transformation Format, little-endian byte order
UTF-16 Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark

No hay comentarios: