Here you can find the source of writeToString(InputStream stream)
public static String writeToString(InputStream stream) throws java.io.IOException
//package com.java2s; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; public class Main { public static String writeToString(InputStream stream) throws java.io.IOException { StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(new InputStreamReader( stream, "utf-8")); char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData);//from w w w. j a v a 2 s . c om buf = new char[1024]; } reader.close(); return fileData.toString(); } }