Java FileChannel Copy copyFileContent(final String sourcePath, final String targetPath)

Here you can find the source of copyFileContent(final String sourcePath, final String targetPath)

Description

copy File Content

License

Open Source License

Declaration

public static boolean copyFileContent(final String sourcePath, final String targetPath) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.nio.channels.FileChannel;

public class Main {
    public static boolean copyFileContent(final String sourcePath, final String targetPath) {
        FileInputStream fr = null;
        FileOutputStream fw = null;
        try {/*from  ww  w  . j  a v  a2s.  c  o m*/
            fr = new FileInputStream(sourcePath);
            fw = new FileOutputStream(targetPath);
            final FileChannel src = fr.getChannel();
            final FileChannel dest = fw.getChannel();
            dest.transferFrom(src, 0, src.size());
            return true;
        } catch (final Exception e) {
            return false;
        } finally {
            try {
                fr.close();
                fw.close();
            } catch (final Exception e) {
                return false;
            }
        }
    }
}

Related

  1. copyFile(String sourceFileName, String destinationFileName)
  2. copyFile(String src, String dest)
  3. copyFile(String srcFileName, String desFileName)
  4. copyFile(String srcPath, String destPath)
  5. copyFileByChannel(String srcFileName, String dstFileName)
  6. copyFileIntoProjectFolder(String projectName, File file)
  7. copyFileLocking(File copyFrom, File copyTo)
  8. copyFileNIO(File src, File dest)
  9. copyFileNio(File src, File dst)