Here you can find the source of getFileContent(String fileName)
public static String getFileContent(String fileName)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { public static String getFileContent(String fileName) { try {/*from w w w. j a va 2s . co m*/ return getFileContent(new FileInputStream(fileName)); } catch (FileNotFoundException e1) { return ""; } } public static String getFileContent(InputStream is) { BufferedReader reader = null; StringBuilder fileContent = new StringBuilder(); try { reader = new BufferedReader(new InputStreamReader(is)); String line = ""; while ((line = reader.readLine()) != null) { fileContent.append(line); fileContent.append("\n"); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close(); reader = null; } } catch (IOException e) { e.printStackTrace(); } } return fileContent.toString(); } }