Here you can find the source of loadText(InputStream in)
public static String loadText(InputStream in) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { /**/*from w w w. jav a 2 s . c o m*/ * Loads the entire stream into memory as a String and returns it. * <p/> * <b>Notice:</b> This implementation appends a <tt>\n</tt> as line * terminator at the of the text. */ public static String loadText(InputStream in) throws IOException { StringBuilder builder = new StringBuilder(); try (InputStreamReader isr = new InputStreamReader(in)) { BufferedReader reader = new BufferedReader(isr); while (true) { String line = reader.readLine(); if (line != null) { builder.append(line); builder.append("\n"); } else { break; } } } return builder.toString(); } }