Skip to content

Instantly share code, notes, and snippets.

View paulofilipe's full-sized avatar

Paulo Filipe Dantas paulofilipe

View GitHub Profile
public static void main(String[] args) {
Charset charset = Charset.forName("ISO-8859-1");
CharsetEncoder encoder = charset.newEncoder();
byte[] b = null;
try {
// Convert a string to ISO-8859-1 bytes in a ByteBuffer
ByteBuffer bbuf = encoder.encode(CharBuffer.wrap("hello world"));
b = bbuf.array();
} catch (CharacterCodingException e) {
System.out.println(e.getMessage());