Here you can find the source of getFileContents(String path)
public static String getFileContents(String path) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.FileSystems; import java.nio.file.Files; public class Main { public static String getFileContents(String path) throws IOException { String returnString = null; File file = new File(path); if (file.exists() && file.isFile()) { BufferedReader fileBufferedReader = null; try { fileBufferedReader = Files.newBufferedReader((FileSystems.getDefault().getPath(path)), Charset.forName("utf-8")); StringBuffer sb = new StringBuffer(); String line = null; while ((line = fileBufferedReader.readLine()) != null) { sb.append(line).append("\n"); }//w w w. j a v a2s . co m if (sb.length() > 0) { returnString = sb.toString(); } } finally { if (fileBufferedReader != null) { fileBufferedReader.close(); } } } return returnString; } }