Java FileChannel Copy copy(String fromPath, String toPath)

Here you can find the source of copy(String fromPath, String toPath)

Description

copy

License

Open Source License

Declaration

public static final void copy(String fromPath, String toPath) throws IOException 

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;

public class Main {

    public static final void copy(String fromPath, String toPath) throws IOException {
        File sourceFile = new File(fromPath);
        FileInputStream input = null;
        FileOutputStream output = null;
        FileChannel fcin = null;// ww w.  j a  v  a  2  s .c  o m
        FileChannel fcout = null;
        input = new FileInputStream(sourceFile);
        output = new FileOutputStream(toPath);
        fcin = input.getChannel();
        fcout = output.getChannel();
        long size = fcin.size();
        fcin.transferTo(0, size, fcout);
        fcout.close();
        output.close();
        input.close();
    }
}

Related

  1. copy(final File fromFile, final File toFile)
  2. copy(final File source, final File dest)
  3. copy(final File src, File dst, final boolean overwrite)
  4. copy(final String aSrcPath, final String aDestPath)
  5. copy(final String aSrcPath, final String aDestPath)
  6. copy(String source, String destination)
  7. copy(String source, String destination, boolean recursive)
  8. copy(String sourceFile, String targetFile)
  9. copy0(File src, File dest)