Java tutorial
//package com.java2s; //License from project: LGPL import java.io.UnsupportedEncodingException; public class Main { /** * Returns the passed string as a byte array containing the * string in UTF-8 representation. * @param str Java string * @return UTF-8 byte array */ public static byte[] getUtf8Bytes(String str) { try { return str.getBytes("UTF-8"); } catch (UnsupportedEncodingException uee) { return str.getBytes(); } } }