Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { public static final String DEFAULT_CHARSET = "UTF-8"; public static byte[] toBytes(String str) { try { return str.getBytes(DEFAULT_CHARSET); } catch (UnsupportedEncodingException e) { return str.getBytes(); } } }