Javaバイト配列からStringへ

824 ワード

回転:http://www.mkyong.com/java/how-do-convert-byte-array-to-string-in-java/
これはいけません。
String s = new String(bytes);
このように、バイト配列から明示的にnew 1つのStering:
public class TestByte
{    
	public static void main(String[] argv) {
 
		String example = "This is an example";
		byte[] bytes = example.getBytes();

		System.out.println("Text : " + example);
		System.out.println("Text [Byte Format] : " + bytes);
		System.out.println("Text [Byte Format] : " + bytes.toString());

		String s = new String(bytes);
		System.out.println("Text Decryted : " + s);

	}
}
結果:
Text : This is an example
Text [Byte Format] : [B@187aeca
Text [Byte Format] : [B@187aeca
Text Decryted : This is an example