Java tutorial
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; public class Main { public static String toString(InputStream is) { StringBuilder out = new StringBuilder(); char[] buffer = new char[512]; if (is != null) { try { Reader in = new InputStreamReader(is, "UTF-8"); try { int n; while ((n = in.read(buffer, 0, buffer.length)) >= 0) { out.append(buffer, 0, n); } } finally { in.close(); } } catch (IOException ex) { out.append("error"); } } return out.toString(); } }