Android Byte Array to Char Convert bytetoChar(byte[] bytes)

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

Description

byteto Char

Declaration

public static char[] bytetoChar(byte[] bytes) 

Method Source Code

//package com.java2s;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;

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

    public static char[] bytetoChar(byte[] bytes) {
        Charset cs = Charset.forName(DEFAULT_CHARSET);
        ByteBuffer bb = ByteBuffer.allocate(bytes.length);
        bb.put(bytes);//ww w. ja va2 s  .c o  m
        bb.flip();
        CharBuffer cb = cs.decode(bb);

        return cb.array();

    }
}

Related

  1. getChar(byte[] b, int index)
  2. getChar(byte[] bytes)