Here you can find the source of readFile(final File inputFile)
static String readFile(final File inputFile) throws IOException
//package com.java2s; /**/*from www .j a v a 2 s .co m*/ * TaskUtils.java * * Copyright (C) 2010, Volker Boerchers * * Translator.java 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, either version 3 of the License, or * (at your option) any later version. * * Translator.java 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. */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { static String readFile(final File inputFile) throws IOException { InputStreamReader in = null; try { in = new InputStreamReader(new FileInputStream(inputFile), "US-ASCII"); StringBuilder builder = new StringBuilder(); final char[] buf = new char[1024]; int len; while ((len = in.read(buf)) > 0) { builder.append(buf, 0, len); } return builder.toString(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // can't help it } } } } }