Java tutorial
//package com.java2s; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; public class Main { private static byte[] encode(final Charset charset, final String string) { ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); return encoded.array(); } }