Here you can find the source of getFileContent(String fileName)
public static String getFileContent(String fileName)
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { public static String getFileContent(String fileName) { BufferedReader reader = null; StringBuilder fileContent = new StringBuilder(); try {//www .jav a 2s .c o m File f = new File(fileName); reader = new BufferedReader(new FileReader(f)); 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(); } 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(); } }