Java Byte Array to String by Charset byteToString(byte[] b, String charset)

Here you can find the source of byteToString(byte[] b, String charset)

Description

byte To String

License

Open Source License

Declaration

public static String byteToString(byte[] b, String charset) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

public class Main {
    public static Charset CHARSET = Charset.forName("utf-8");

    public static String byteToString(byte[] b) {
        return new String(b, CHARSET);
    }//from w w w.  j  av a  2 s . c om

    public static String byteToString(byte[] b, String charset) {
        try {
            return new String(b, charset);
        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }

    public static String byteToString(byte[] b, Charset charset) {
        return new String(b, charset);
    }
}

Related

  1. asBytes(String string, Charset charset)
  2. bytesToString(byte[] bytes, Charset charset)
  3. byteToString(Charset charset, byte[] data)
  4. changeEncoding(byte[] byteArray, Charset charsetFrom, Charset charsetTo)
  5. charSequence2Bytes(CharSequence sb, Charset charset)
  6. charSetForBOM(byte[] buffer, int offset)