Java File to Byte Array fileToByteArray(final IFile file)

Here you can find the source of fileToByteArray(final IFile file)

Description

file To Byte Array

License

Open Source License

Declaration

public static byte[] fileToByteArray(final IFile file)
            throws CoreException, IOException 

Method Source Code

//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();
        }
    }
}

Related

  1. fileToByteArray(File file)
  2. FiletoByteArray(File file)
  3. fileToByteArray(File file)
  4. fileToByteArray(File file)
  5. fileToByteArray(final File f)
  6. fileToByteArray(String filePath)
  7. fileToByteArray(String fname)
  8. fileToByteArray(String path)
  9. fileToBytes(File file)