Here you can find the source of readFile(File file)
public static String readFile(File file)
//package com.java2s; /*//from ww w .jav a 2 s . c o m * Copyright (c) 2014 Eike Stepper (Berlin, Germany) and others. * 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: * Eike Stepper - initial API and implementation */ import java.io.Closeable; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.Reader; public class Main { public static String readFile(File file) { char[] buffer = new char[(int) file.length()]; Reader reader = null; try { reader = new FileReader(file); reader.read(buffer); return new String(buffer); } catch (IOException ex) { throw new RuntimeException(ex); } finally { close(reader); } } public static void close(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException ex) { ex.printStackTrace(); } } } }