Here you can find the source of toUTF8(String string)
Parameter | Description |
---|---|
string | String. |
public static byte[] toUTF8(String string)
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { public static final String UTF_8_ENCODING = "UTF-8"; /**/*from w ww. ja va 2 s .com*/ * Convert from a String to UTF-8 bytes. * * @param string String. * @return UTF-8 bytes. */ public static byte[] toUTF8(String string) { if (string == null) { return null; } try { return string.getBytes(UTF_8_ENCODING); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("UTF-8 not supported?", e); } } }