Here you can find the source of getBytesUtf8(String string)
Parameter | Description |
---|---|
string | the String to encode, may be null |
public static byte[] getBytesUtf8(String string)
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { /**//ww w . j a v a2s . co m * Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte * array. * * @param string * the String to encode, may be {@code null} * @return encoded bytes, or {@code null} if the input string was {@code null} */ public static byte[] getBytesUtf8(String string) { try { return string == null ? null : string.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { // Should never happen with UTF-8 // If it does - ignore & return null } return null; } }