Here you can find the source of getBytesFromFile(File f)
private static byte[] getBytesFromFile(File f) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2010 BEA Systems, Inc, IBM Corporation, 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:/*ww w .java 2 s . c om*/ * mkaufman@bea.com - initial API and implementation * *******************************************************************************/ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { private static byte[] getBytesFromFile(File f) throws IOException { FileInputStream fis = null; ByteArrayOutputStream baos = null; byte[] rtrn = new byte[0]; try { fis = new FileInputStream(f); baos = new ByteArrayOutputStream(); int b; while ((b = fis.read()) != -1) baos.write(b); rtrn = baos.toByteArray(); } finally { if (fis != null) fis.close(); if (baos != null) baos.close(); } return rtrn; } }