Here you can find the source of readAllText(InputStream stream)
public static String readAllText(InputStream stream) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { public static String readAllText(File file) throws IOException { InputStream stream = new FileInputStream(file); try {//w w w . j a v a 2 s . c om return readAllText(stream); } finally { stream.close(); } } /** * Reads all text from the stream using the default charset. Does not close * the stream. */ public static String readAllText(InputStream stream) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); StringBuilder result = new StringBuilder(); while (true) { String s = reader.readLine(); if (s == null) { return result.toString(); } result.append(s); result.append('\n'); } } }