Java tutorial
//package com.java2s; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; public class Main { public static byte[] char2byte(String encode, char... chars) { Charset cs = Charset.forName(encode); CharBuffer cb = CharBuffer.allocate(chars.length); cb.put(chars); cb.flip(); ByteBuffer bb = cs.encode(cb); return bb.array(); } }