Here you can find the source of loadFile(File logfile, Charset charset)
public static String loadFile(File logfile, Charset charset) throws IOException
//package com.java2s; /******************************************************************************* * * Copyright (c) 2004-2011 Oracle Corporation. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: //from w w w .j ava2s. c o m * * Kohsuke Kawaguchi, Winston Prakash * * *******************************************************************************/ import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.FileInputStream; import java.nio.charset.Charset; public class Main { /** * Loads the contents of a file into a string. */ public static String loadFile(File logfile) throws IOException { return loadFile(logfile, Charset.defaultCharset()); } public static String loadFile(File logfile, Charset charset) throws IOException { if (!logfile.exists()) { return ""; } StringBuilder str = new StringBuilder((int) logfile.length()); BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(logfile), charset)); char[] buf = new char[1024]; int len; while ((len = r.read(buf, 0, buf.length)) > 0) { str.append(buf, 0, len); } r.close(); return str.toString(); } }