Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static String toString(InputStream is) throws IOException { final ByteArrayOutputStream baos = toByteArrayOutputStream(is); return (baos != null) ? baos.toString() : null; } public static ByteArrayOutputStream toByteArrayOutputStream(InputStream is) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final byte[] buffer = new byte[512]; int length = 0; while ((length = is.read(buffer)) != -1) { baos.write(buffer, 0, length); } return baos; } }