Java FileInputStream Copy copyFileToContainer(File pChild, IContainer pContainer)

Here you can find the source of copyFileToContainer(File pChild, IContainer pContainer)

Description

copy File To Container

License

Open Source License

Declaration

private static void copyFileToContainer(File pChild, IContainer pContainer) throws Exception 

Method Source Code


//package com.java2s;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;

import org.eclipse.core.runtime.CoreException;

import org.eclipse.core.runtime.Path;

public class Main {
    private static void copyFileToContainer(File pChild, IContainer pContainer) throws Exception {
        if (pChild.isDirectory()) {
            internalCopyFolderToContainer(pChild, pContainer);
        } else {//  w ww.j  a va 2 s .  c o m
            internalCopyFileToContainer(pChild, pContainer);
        }
    }

    private static void internalCopyFolderToContainer(File pChild, IContainer pContainer)
            throws CoreException, Exception {
        IFolder folder = pContainer.getFolder(new Path(pChild.getName()));
        folder.create(true, true, null);

        for (File child : pChild.listFiles()) {
            copyFileToContainer(child, folder);
        }
    }

    private static void internalCopyFileToContainer(File pChild, IContainer pContainer)
            throws FileNotFoundException, CoreException {
        InputStream in = new FileInputStream(pChild);
        IFile newFile = pContainer.getFile(new Path(pChild.getName()));
        newFile.create(in, true, null);
    }
}

Related

  1. copyFileFromTo(String filename, File fromDir, File toDir)
  2. copyFileLowLevel(File source, File target)
  3. copyFileR(File srcFile, File destDirectory)
  4. copyFileRecursive(File src, File dest)
  5. copyFileToAnotherDirWithRelativePaths(File srcDir, File destDir, File originalFile)
  6. copyFileToDestDir(String srcFilePath, String destFileDir)
  7. copyFileToDir(File oldFile, File outputDir)
  8. copyFileToDir(File sourceFile, File destDir)
  9. copyFileToDir(String targetDir, String[] filePath)