Here you can find the source of readFile(InputStream in)
public static String readFile(InputStream in) throws IOException
//package com.java2s; 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 readFile(InputStream in) throws IOException { StringBuffer sb = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); try {//from w w w. j av a 2s. c om readFile(reader, sb); } finally { reader.close(); } return sb.toString(); } public static String readFile(File f) throws IOException { StringBuffer sb = new StringBuffer(); InputStream in = new FileInputStream(f); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); try { readFile(reader, sb); } finally { reader.close(); } return sb.toString(); } public static void readFile(BufferedReader reader, StringBuffer sb) throws IOException { String line = null; do { line = reader.readLine(); if (line != null) { sb.append(line); sb.append("\n"); } } while (line != null); } }