Android Byte Array to String Convert bytes2String(byte[] data)

Here you can find the source of bytes2String(byte[] data)

Description

bytes String

Declaration

public static String bytes2String(byte[] data) 

Method Source Code

//package com.java2s;
import java.io.UnsupportedEncodingException;

public class Main {
    public static String bytes2String(byte[] data) {
        String result = null;//from   w  w  w .  j a v  a  2 s.c  o  m
        int availableLen = data.length;

        for (int i = 0; i < availableLen; i++) {
            if (data[i] == 0) {
                availableLen = i;
                break;
            }
        }

        try {
            if (availableLen == 1) {
                result = String.valueOf((int) data[0]);
            } else {
                result = new String(data, 0, availableLen, "UTF-8");
            }

        } catch (UnsupportedEncodingException e) {
            return null;
        }

        return result;
    }
}

Related

  1. Bcd2Str(byte[] b)
  2. ByteArrayToString(byte[] input)
  3. byteArrayToString(byte[] b)
  4. byteArrayToString(byte[] bytes)
  5. byteToString(byte b)
  6. bytes2String(byte[] data, String type)
  7. bytes2StringPtr(byte[] data, String type)
  8. getString(byte[] bb)
  9. getString(byte[] bytes)