Java Byte Array to String ASCIIByteArrayToString(byte[] data)

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

Description

Convert a byte array into a 2 byte per character Java String by adding a 0-byte in front of each byte.

License

Open Source License

Parameter

Parameter Description
data the input byte array

Return

the Java String

Declaration

public static String ASCIIByteArrayToString(byte[] data) 

Method Source Code

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

public class Main {
    /**//from ww  w.  j ava2  s  .c  o  m
     * Convert a byte array into a 2 byte per character Java String by adding a
     * 0-byte in front of each byte.
     * 
     * @param data
     *            the input byte array
     * @return the Java String
     */
    public static String ASCIIByteArrayToString(byte[] data) {
        StringBuilder r = new StringBuilder("");

        for (byte b : data) {
            r.append((char) (b & 0xFF));
        }

        return r.toString();
    }
}

Related

  1. arr2String(byte[] arr, int start)
  2. asString(byte[] a, String separator)
  3. asString(byte[] array)
  4. asString(byte[] bs)
  5. asString(byte[] buf)