Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { /** * Get utf8 byte array. * * @param str * should be "UTF-8" encoded * @return array or null if UnsupportedEncodingException was thrown */ public static byte[] getUTF8Bytes(String str) { try { return str.getBytes("UTF-8"); } catch (UnsupportedEncodingException ex) { return null; } } }