Here you can find the source of readFile(File file)
public static byte[] readFile(File file) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2009 Tasktop Technologies 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:/*from w ww .j a v a 2s. c om*/ * Tasktop Technologies - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] readFile(File file) throws IOException { if (file.length() > 10000000) { throw new IOException("File too big: " + file.getAbsolutePath() + ", size: " + file.length()); } byte[] data = new byte[(int) file.length()]; InputStream in = new FileInputStream(file); try { in.read(data); } finally { in.close(); } return data; } }