Android File Copy copyBundleFile(IPath projectRelativePath, String outputPath)

Here you can find the source of copyBundleFile(IPath projectRelativePath, String outputPath)

Description

copy Bundle File

Declaration

public static void copyBundleFile(IPath projectRelativePath,
            String outputPath) throws CoreException 

Method Source Code

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.Bundle;
import ch.hsr.ifs.sconsolidator.core.SConsPlugin;

public class Main{
    public static void copyBundleFile(IPath projectRelativePath,
            String outputPath) throws CoreException {
        InputStream is = null;/*from  w  w w . j  av  a 2s .co m*/
        FileOutputStream to = null;
        try {
            is = FileLocator.openStream(getBundle(), projectRelativePath,
                    false);
            to = new FileOutputStream(outputPath);
            byte[] buffer = new byte[4096];
            int bytesRead;

            while ((bytesRead = is.read(buffer)) != -1) {
                to.write(buffer, 0, bytesRead);
            }
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR,
                    SConsPlugin.PLUGIN_ID, e.getMessage()));
        } finally {
            IOUtil.safeClose(is);
            IOUtil.safeClose(to);
        }
    }
    private static Bundle getBundle() {
        return SConsPlugin.getDefault().getBundle();
    }
}

Related

  1. copy(File src, File dest)
  2. copy(String input, String output)
  3. copy(String pSourceFile, String pTargetFile)
  4. copy(String source, String destinction)
  5. copy(String srcFileName, String destFileName)
  6. copyFile(File fin, File fout)
  7. copyFile(File from, File to)
  8. copyFile(File from, File to, boolean append)
  9. copyFile(File from, File to, byte[] buf)