Java UTF8 Convert To fromUTF8(byte[] bytes)

Here you can find the source of fromUTF8(byte[] bytes)

Description

Convert from UTF-8 bytes to a String.

License

Open Source License

Parameter

Parameter Description
bytes UTF-8 bytes.

Return

a String.

Declaration

public static String fromUTF8(byte[] bytes) 

Method Source Code

//package com.java2s;

import java.io.UnsupportedEncodingException;

public class Main {
    public static final String UTF_8_ENCODING = "UTF-8";

    /**//from  ww w. ja  v  a 2 s.  c om
     * Convert from UTF-8 bytes to a String.
     * 
     * @param bytes UTF-8 bytes.
     * @return a String.
     */
    public static String fromUTF8(byte[] bytes) {
        if (bytes == null) {
            return null;
        }
        try {
            return new String(bytes, UTF_8_ENCODING);
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException("UTF-8 not supported?", e);
        }
    }
}

Related

  1. fromUTF8(byte[] b)
  2. fromUTF8(byte[] bytes)
  3. fromUTF8(byte[] bytes)
  4. fromUTF8Bytes(byte[] bytes)
  5. fromUTF8Bytes(byte[] bytes)
  6. getBytesUtf8(String str)
  7. getBytesUTF8(String string)