Here you can find the source of readFile(String path)
Copied from http://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file
public static String readFile(String path)
//package com.java2s; /* license-start// w w w . j a v a 2 s. c o m * * Copyright (C) 2008 - 2013 Crispico Software, <http://www.crispico.com/>. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details, at <http://www.gnu.org/licenses/>. * * license-end */ import java.io.FileInputStream; import java.io.InputStreamReader; public class Main { /** * Copied from http://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file */ public static String readFile(String path) { StringBuffer loadedContent = new StringBuffer(); try { InputStreamReader fileEditorInputReader = new InputStreamReader(new FileInputStream(path)); char[] buffer = new char[1024]; int bytesRead; do { bytesRead = fileEditorInputReader.read(buffer); if (bytesRead > 0) loadedContent.append(buffer, 0, bytesRead); } while (bytesRead > 0); fileEditorInputReader.close(); } catch (Exception e) { throw new RuntimeException("Error while loading file content " + path, e); } return loadedContent.toString(); } }