Here you can find the source of readFileSB(File f)
public static StringBuffer readFileSB(File f) 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 StringBuffer readFileSB(File f) throws IOException { InputStream in = new FileInputStream(f); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuffer sb = new StringBuffer(); try {//from ww w.j av a2 s . com readFile(reader, sb); } finally { reader.close(); } return sb; } public static String readFile(InputStream in) throws IOException { StringBuffer sb = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); try { 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); } }