Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { public static byte[] getBytes(final String data, String charset) { if (data == null) { throw new IllegalArgumentException("data may not be null"); } if (charset == null || charset.length() == 0) { throw new IllegalArgumentException("charset may not be null or empty"); } try { return data.getBytes(charset); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(String.format("Unsupported encoding: %s", charset)); } } }