Here you can find the source of readFileAsString(String path)
public static String readFileAsString(String path) throws IOException
//package com.java2s; //License from project: Apache 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 readFileAsString(String path) throws IOException { StringBuffer sb = new StringBuffer(); InputStream in = new FileInputStream(path); BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); String line = ""; while ((line = reader.readLine()) != null) { line = line.trim();//from w ww.j av a 2s . c o m if (line == null || "".equals(line)) { continue; } sb.append(line); } reader.close(); return sb.toString(); } public static String readFileAsString(File file) throws IOException { StringBuffer sb = new StringBuffer(); InputStream in = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); String line = ""; while ((line = reader.readLine()) != null) { line = line.trim(); if (line == null || "".equals(line)) { continue; } sb.append(line); } reader.close(); return sb.toString(); } }