Skip to content

Java.lang.String

inputStream to String

StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = inputStream.read(b)) != -1;) {
    out.append(new String(b, 0, n));
}
out.toString();

String to inputStream

InputStream bai = new ByteArrayInputStream(out.toString().getBytes("UTF-8"));

Byte Array to String

Byte 배열로 표현된 문자열을 String으로 변환하는 방법.

// byte[] a 에 값이 들어 있을 때
String str = new String(a);

참고로, Byte 배열로 표현된 정수를 int로 변환하는 방법은 다음과 같다:

// byte num[]에 값이 들어있을때
ByteBuffer bytebuf = ByteBuffer.allocate(512);
bytebuf.put(num);
int intnum = bytebuf.getInt();

숫자(Valueable)를 문자열(String)로 변환하는 방법

Favorite site