Here you can find the source of stringToUtf8(String str)
Parameter | Description |
---|---|
str | the string that will be encoded. |
Parameter | Description |
---|---|
UnsupportedCharsetException | if the Java implementation does not support the UTF-8 character encoding, which is requiredof all Java implementations. |
public static byte[] stringToUtf8(String str)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.nio.charset.UnsupportedCharsetException; public class Main { public static final String ENCODING_NAME_UTF8 = "UTF-8"; /**//from w w w. j a va2 s .com * Encodes the specified string as a UTF-8 sequence. * * @param str the string that will be encoded. * @return an array containing the UTF-8 sequence that results from encoding the input string. * @throws UnsupportedCharsetException * if the Java implementation does not support the UTF-8 character encoding, which is required * of all Java implementations. */ public static byte[] stringToUtf8(String str) { try { return str.getBytes(ENCODING_NAME_UTF8); } catch (UnsupportedEncodingException e) { throw new UnsupportedCharsetException(ENCODING_NAME_UTF8); } } }