Java tutorial
import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; public class Main { public static void main(String[] args) throws Exception { String os = "abc"; for (byte b : os.getBytes("UTF-16BE")) { System.out.println(b); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (char c : os.toCharArray()) { dos.writeChar(c); } byte[] ba = baos.toByteArray(); for (byte b : ba) { System.out.println(b); } } }