Here you can find the source of toUTF8Bytes(String string)
public static byte[] toUTF8Bytes(String string)
//package com.java2s; /*//from w ww .j a v a2 s .co m * Copyright (C) 2009 by Eric Herman <eric@freesa.org> * Use and distribution licensed under the * GNU Lesser General Public License (LGPL) version 2.1. * See the COPYING file in the parent directory for full text. */ import java.io.UnsupportedEncodingException; public class Main { public static final String CHARSET_UTF_8 = "UTF-8"; public static byte[] toUTF8Bytes(String string) { return toBytes(string, CHARSET_UTF_8); } public static byte[] toBytes(String string, String encoding) { try { return string.getBytes(encoding); } catch (UnsupportedEncodingException noAscii) { throw new IllegalArgumentException("Runtime does not support" + " encoding " + encoding, noAscii); } } }