Java UTF8 Encode toUTF8(String string)

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

Description

Convert from a String to UTF-8 bytes.

License

Open Source License

Parameter

Parameter Description
string String.

Return

UTF-8 bytes.

Declaration

public static byte[] toUTF8(String string) 

Method Source Code

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

Related

  1. toUTF8(String sourceStr)
  2. toUTF8(String str)
  3. toUtf8(String str)
  4. toUTF8(String str)
  5. toUTF8(String str)
  6. toUTF8(String value)
  7. toUTF8ByteArray(char[] string)
  8. toUTF8Bytes(final String s)
  9. toUTF8Bytes(String src)