Java Byte Array Convert To bytesToChars(byte[] data, String enc)

Here you can find the source of bytesToChars(byte[] data, String enc)

Description

Convert byte array to char array

License

Open Source License

Parameter

Parameter Description
data the byte array
enc its encoding

Return

the equivalent char array

Declaration

public static char[] bytesToChars(byte[] data, String enc) 

Method Source Code

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

public class Main {
    /**/*from w w w  .j av  a2s  .  c  o m*/
     * Convert byte array to char array
     * @param data the byte array
     * @param enc its encoding
     * @return the equivalent char array
     */
    public static char[] bytesToChars(byte[] data, String enc) {
        String str;
        try {
            str = new String(data, enc);
        } catch (Exception e) {
            str = new String(data);
        }
        char[] chars = new char[str.length()];
        str.getChars(0, chars.length, chars, 0);
        return chars;
    }
}

Related

  1. bytesToBlocks(final long bytes, final int blockSize)
  2. bytesToBool(byte[] data, int[] offset)
  3. bytesToBoxingBytes(final byte[] bytes)
  4. BytesTobytes(Byte[] bytes)
  5. bytesToChars(byte[] bytes)
  6. bytesToCharset(final byte[] bytes, final String charset)
  7. bytesToCompressedBases(final byte[] readBases)
  8. bytesToCompressedBases(final byte[] readBases)
  9. bytesToData(byte[][] fileData)