Java FileChannel Copy copyFileIntoProjectFolder(String projectName, File file)

Here you can find the source of copyFileIntoProjectFolder(String projectName, File file)

Description

copy File Into Project Folder

License

Open Source License

Declaration

public static void copyFileIntoProjectFolder(String projectName, File file) 

Method Source Code


//package com.java2s;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Platform;

public class Main {
    public static void copyFileIntoProjectFolder(String projectName, File file) {
        FileChannel inChannel = null;
        FileChannel outChannel = null;

        List<File> libraryFiles = new ArrayList<File>();
        FileInputStream istream = null;
        FileOutputStream ostream = null;
        try {/*from  w  w w. j  av  a  2  s.  c  o  m*/
            File out = new File(Platform.getLocation() + File.separator + projectName + File.separator
                    + File.separator + file.getName());

            istream = new FileInputStream(file);
            ostream = new FileOutputStream(out);

            inChannel = istream.getChannel();
            outChannel = ostream.getChannel();

            inChannel.transferTo(0, inChannel.size(), outChannel);
            libraryFiles.add(file);
        } catch (IOException ioException) {

        } finally {
            try {
                if (istream != null) {
                    istream.close();
                }
                if (ostream != null) {
                    ostream.close();
                }
            } catch (IOException ex) {

            }
        }
    }
}

Related

  1. copyFile(String src, String dest)
  2. copyFile(String srcFileName, String desFileName)
  3. copyFile(String srcPath, String destPath)
  4. copyFileByChannel(String srcFileName, String dstFileName)
  5. copyFileContent(final String sourcePath, final String targetPath)
  6. copyFileLocking(File copyFrom, File copyTo)
  7. copyFileNIO(File src, File dest)
  8. copyFileNio(File src, File dst)
  9. copyFileOrDirectory(File source, File destination, boolean flag)