새소식

Java

문자열 - 바이트 배열 변환

  • -

 

public class StringByteArray {
public static void main(String[] args) {
String str1 = "HelloWorld";
// String to Byte Array
byte[] ba = str1.getBytes();
for(byte b : ba){
System.out.println(b);
}
// Byte Array to String
String str2 = new String(ba);
System.out.println(str2);
}
}

 

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.