Java Utililty Methods FileChannel Copy

List of utility methods to do FileChannel Copy

Description

The list of methods to do FileChannel Copy are organized into topic(s).

Method

voidcopyFile(File sourceFile, File destFile)
Faster copying method from http://www.javalobby.org/java/forums/t17036.html
if (!destFile.exists()) {
    destFile.createNewFile();
try (FileChannel source = new FileInputStream(sourceFile).getChannel();
        FileChannel destination = new FileOutputStream(destFile).getChannel()) {
    destination.transferFrom(source, 0, source.size());
} catch (Exception e) {
    System.out.println(e);
...
voidcopyFile(File sourceFile, File destFile)
copy File
if (sourceFile.exists()) {
    System.out.println(sourceFile.getAbsolutePath() + " exists");
    System.out.println("Is directory = " + sourceFile.isDirectory());
    System.out.println("Can read = " + sourceFile.canRead());
if (!destFile.exists()) {
    destFile.createNewFile();
FileChannel source = null;
FileChannel destination = null;
try {
    FileInputStream inStream = new FileInputStream(sourceFile);
    source = inStream.getChannel();
    destination = new FileOutputStream(destFile).getChannel();
    destination.transferFrom(source, 0, source.size());
} finally {
    if (source != null) {
        source.close();
    if (destination != null) {
        destination.close();
voidcopyFile(File sourceFile, File destFile)
copy File
if (!destFile.exists()) {
    destFile.createNewFile();
FileInputStream fIn = null;
FileOutputStream fOut = null;
FileChannel source = null;
FileChannel destination = null;
try {
...
voidcopyFile(File sourceFile, File destFile)
Copies a file
FileChannel source = null;
FileChannel destination = null;
try {
    source = new FileInputStream(sourceFile).getChannel();
    destination = new FileOutputStream(destFile).getChannel();
    destination.transferFrom(source, 0, source.size());
} finally {
    if (source != null) {
...
voidcopyFile(File sourceFile, File destFile)
(Copied from stackoverflow).
if (!destFile.exists()) {
    destFile.createNewFile();
FileChannel source = null;
FileChannel destination = null;
try {
    source = new FileInputStream(sourceFile).getChannel();
    destination = new FileOutputStream(destFile).getChannel();
...
voidcopyFile(File sourceFile, File destFile)
Copy file from a path to another.
if (!destFile.exists()) {
    destFile.createNewFile();
FileInputStream fin = new FileInputStream(sourceFile);
try {
    FileOutputStream fout = new FileOutputStream(destFile);
    try {
        FileChannel source = fin.getChannel();
...
booleancopyFile(File sourceFile, File destFile)
Copies a single file from one location to another
if (!destFile.exists()) {
    try {
        destFile.createNewFile();
    } catch (IOException e) {
        return false;
FileChannel source = null;
...
voidcopyFile(File sourceFile, File destinationFile)
copy File
copyFile(sourceFile, destinationFile, true);
voidcopyFile(File sourceFile, File destinationFile)
Copy file.
FileInputStream sourceIs = null;
FileChannel source = null;
FileOutputStream destinationOs = null;
FileChannel destination = null;
try {
    sourceIs = new FileInputStream(sourceFile);
    source = sourceIs.getChannel();
    destinationOs = new FileOutputStream(destinationFile);
...
voidcopyFile(File sourceFile, File destinationFile)
copy File
copyFile(sourceFile, destinationFile, true);