Here you can find the source of fileToByteArray(final IFile file)
public static byte[] fileToByteArray(final IFile file) throws CoreException, IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2009 itemis AG (http://www.itemis.eu) 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 *******************************************************************************/ import java.io.IOException; import java.io.InputStream; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import com.google.common.io.ByteStreams; public class Main { public static byte[] fileToByteArray(final IFile file) throws CoreException, IOException { InputStream contents = null; try {// w w w . j a v a 2 s .c om contents = file.getContents(); return ByteStreams.toByteArray(contents); } finally { if (contents != null) contents.close(); } } }