Here you can find the source of loadIfileAsBytes(final IFile ifile)
Parameter | Description |
---|---|
ifile | The ifile object |
Parameter | Description |
---|---|
CoreException | A |
IOException | B |
public static byte[] loadIfileAsBytes(final IFile ifile) throws CoreException, IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; public class Main { /**/* ww w . j av a 2 s . c om*/ * The buffer size. */ private static final int BUF_SIZE = 1024 * 8; /** * Helper to read a ifile from the workspace into a byte array. * * @param ifile The ifile object * @return The file's contents * @throws CoreException A * @throws IOException B */ public static byte[] loadIfileAsBytes(final IFile ifile) throws CoreException, IOException { final InputStream is = ifile.getContents(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final byte[] buffer = new byte[BUF_SIZE]; int num; while ((num = is.read(buffer)) > 0) { baos.write(buffer, 0, num); } is.close(); baos.close(); // effect-less return baos.toByteArray(); } }