Here you can find the source of getUTF8Bytes(String string)
Parameter | Description |
---|---|
string | the string to be converted into bytes. |
public static byte[] getUTF8Bytes(String string)
//package com.java2s; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; public class Main { /** The UTF-8 Charset. */ public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8"); /**//from w w w . j a v a2 s . co m * Converts the string to bytes using the UTF-8 encoding. * @param string the string to be converted into bytes. * @return the corresponding UTF-8-encoded bytes. */ public static byte[] getUTF8Bytes(String string) { try { return string.getBytes(UTF_8_CHARSET.name()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } }