How to convert Byte array to String in Java
byte[]
byte array
string
It is very easy to convert byte[] array to string.
Example
package com.admfactory;
public class ByteArrayToString {
public static void main(String[] args) {
String sample = "Sample text.";
/** byte array */
byte[] array = sample.getBytes();
String str = new String(array);
System.out.println("byte[] array to String example.");
System.out.println();
System.out.println("array: " + array);
System.out.println("string: " + str);
}
}
Output
byte[] array to String example.
array: [B@4669b7fe
string: Sample text.