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 inFile, File outFile)
This method copies one file to another location
if (!inFile.exists()) {
    return false;
FileChannel in = null;
FileChannel out = null;
try {
    in = new FileInputStream(inFile).getChannel();
    out = new FileOutputStream(outFile).getChannel();
...
voidcopy(File input, File output)
copy
FileInputStream fis = new FileInputStream(input);
FileOutputStream fos = new FileOutputStream(output);
try {
    FileChannel ic = fis.getChannel();
    FileChannel oc = fos.getChannel();
    try {
        oc.transferFrom(ic, 0, ic.size());
    } finally {
...
voidcopy(File inputFile, OutputStream out)
copy
copy(inputFile, out, false);
voidcopy(File source, File dest)
copy
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
    inputChannel = new FileInputStream(source).getChannel();
    outputChannel = new FileOutputStream(dest).getChannel();
    outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} finally {
    inputChannel.close();
...
voidcopy(File source, File dest)
copy
Files.copy(source.toPath(), dest.toPath());
if (source.isDirectory()) {
    for (String s : source.list()) {
        copy(new File(source, s), new File(dest, s));
voidcopy(File source, File dest)
Copy a file.
Files.copy(source.toPath(), dest.toPath());
voidcopy(File source, File dest)
copy
FileChannel in = null, out = null;
try {
    in = new FileInputStream(source).getChannel();
    out = new FileOutputStream(dest).getChannel();
    long size = in.size();
    MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
    out.write(buf);
} finally {
...
voidcopy(File source, File dest)
Copy a file from the source file to the destination file.
if (source.isDirectory()) {
    dest.mkdir();
    for (File child : listFiles(source)) {
        copy(child, new File(dest, child.getName()));
} else {
    if (source.exists()) {
        long lm = source.lastModified();
...
voidcopy(File source, File dest, boolean preserveTime)
Copies file source to location dest.
FileChannel in = null, out = null;
try {
    dest.getParentFile().mkdirs();
    in = new FileInputStream(source).getChannel();
    out = new FileOutputStream(dest).getChannel();
    long size = in.size();
    MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
    out.write(buf);
...
voidcopy(File source, File destination)
copy
if (source.isDirectory()) {
    copyDirectory(source, destination);
} else {
    copyFile(source, destination);