Skip to content
Search

Java.lang.String

lastmod 2020-09-09created 2014-06-065 edits

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

How to convert a string represented as a Byte array to a String.

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

For reference, an integer represented as a Byte array can be converted to an int as follows:

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

How to convert a number (Valueable) to a string (String)

Favorite site

author Zer0 sitemap