Java Utililty Methods File Copy nio

List of utility methods to do File Copy nio

Description

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

Method

booleancopy(File sourceFile, File destFile)
copy
try {
    copyFile(sourceFile, destFile);
    return true;
} catch (IOException ioe) {
    System.out.println("File copy failed: " + ioe);
    return false;
voidcopy(File sourceFile, File destinationFile)
Copies one file to another.
FileChannel sourceChannel = null;
FileChannel destinationChannel = null;
try {
    sourceChannel = new FileInputStream(sourceFile).getChannel();
    destinationChannel = new FileOutputStream(destinationFile).getChannel();
    destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
} finally {
    if (sourceChannel != null) {
...
voidcopy(File sourceFile, File targetFile)
copy
FileChannel sourceChannel = null;
FileChannel targetChannel = null;
try {
    sourceChannel = new FileInputStream(sourceFile).getChannel();
    targetChannel = new FileOutputStream(targetFile).getChannel();
    targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
} finally {
    if (sourceChannel != null)
...
voidcopy(File src, File dest)
copy
if (!src.exists())
    return;
if (!dest.exists())
    dest.mkdir();
for (File f : src.listFiles()) {
    File target = new File(dest, f.getName());
    if (f.isDirectory())
        copy(f, target);
...
voidcopy(File src, File dest)
copy
if (src.isDirectory()) {
    if (!dest.exists()) {
        dest.mkdir();
    String files[] = src.list();
    for (String file : files) {
        File srcFile = new File(src, file);
        File destFile = new File(dest, file);
...
voidcopy(File src, File dest)
copy
FileInputStream in = null;
FileOutputStream out = null;
try {
    in = new FileInputStream(src);
    out = new FileOutputStream(dest);
    copyInternal(in, out);
} finally {
    if (in != null) {
...
booleancopy(File src, File dest)
Copy the specified file or directory to the destination.
boolean result = true;
String files[] = null;
if (src.isDirectory()) {
    files = src.list();
    result = dest.mkdir();
} else {
    files = new String[1];
    files[0] = "";
...
booleancopy(File src, File dist)
copy
FileInputStream fis = null;
FileChannel in = null;
FileOutputStream fos = null;
FileChannel out = null;
try {
    fis = new FileInputStream(src);
    in = fis.getChannel();
    fos = new FileOutputStream(dist);
...
voidcopy(File src, File dst)
Writes a copy of a file.
copy(src, dst, false);
voidcopy(File src, File dst)
Copy the content of file src to dst TODO since java 1.7 this is provided in java.nio.file.Files
FileChannel source = null;
FileChannel destination = null;
try {
    source = new FileInputStream(src).getChannel();
    destination = new FileOutputStream(dst).getChannel();
    destination.transferFrom(source, 0, source.size());
} finally {
    if (source != null) {
...