Java Byte Array to String bytesToString(byte[] bytes, String encoding)

Here you can find the source of bytesToString(byte[] bytes, String encoding)

Description

bytes To String

License

Apache License

Declaration

public static String bytesToString(byte[] bytes, String encoding) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String bytesToString(byte[] bytes, String encoding) {
        if (bytes == null) {
            throw new IllegalArgumentException(
                    "bytes may not be null in string conversion");
        }/*from   w w  w  .  j  av  a 2 s .c  o  m*/

        if (bytes.length == 0) {
            return null;
        }

        try {
            return new String(bytes, encoding);
        } catch (Exception e) {
            throw new IllegalArgumentException("Unknown encoding");
        }
    }

    public static String bytesToString(byte[] bytes) {
        return bytesToString(bytes, "ASCII");
    }
}

Related

  1. bytesToString(byte[] bytes)
  2. bytesToString(byte[] bytes)
  3. bytesToString(byte[] bytes)
  4. bytesToString(byte[] bytes, int offs, int len)
  5. bytesToString(byte[] bytes, int startIndex)
  6. bytesToString(byte[] data)
  7. bytesToString(byte[] data, int start, int end)
  8. bytesToString(byte[] hasher)
  9. bytesToString(byte[] id)