Java UTF8 getUTF8Bytes(String string)

Here you can find the source of getUTF8Bytes(String string)

Description

Converts the string to bytes using the UTF-8 encoding.

License

Open Source License

Parameter

Parameter Description
string the string to be converted into bytes.

Return

the corresponding UTF-8-encoded bytes.

Declaration

public static byte[] getUTF8Bytes(String string) 

Method Source Code

//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);
        }
    }
}

Related

  1. getUtf8()
  2. getUTF8(byte[] data, int offset, int length)
  3. getUTF8Bytes(String s)
  4. getUtf8Bytes(String s)
  5. GetUtf8Bytes(String str, boolean replace)
  6. getUTF8BytesFromString(String str)
  7. getUtf8Decoder()
  8. getUtf8OrDefault()
  9. getUTF8Reader(InputStream f)