Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Pursuer (http://pursuer.me). * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Pursuer - initial API and implementation ******************************************************************************/ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { public static String readFromFile(final File file) { final StringBuilder ret = new StringBuilder(); try { final BufferedReader input = new BufferedReader(new FileReader(file), 4096); int len; final char buff[] = new char[4096]; while ((len = input.read(buff, 0, 4096)) != -1) { ret.append(buff, 0, len); } input.close(); } catch (final IOException exception) { exception.printStackTrace(); } return ret.toString(); } }