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 source, File dest)
copy File
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
    try {
        inputChannel = new FileInputStream(source).getChannel();
        outputChannel = new FileOutputStream(dest).getChannel();
        outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
    } finally {
...
voidcopyFile(File source, File dest)
Copies one file to another one.
if (dest.exists())
    throw new IOException("Destination file already exists.");
FileChannel in = null;
FileChannel out = null;
try {
    in = new FileInputStream(source).getChannel();
    out = new FileOutputStream(dest).getChannel();
    long size = in.size();
...
voidcopyFile(File source, File dest)
copy File
if (!source.exists())
    return;
if (!dest.exists()) {
    dest.getParentFile().mkdirs();
    dest.createNewFile();
FileChannel srcChannel = new FileInputStream(source).getChannel();
FileChannel dstChannel = new FileOutputStream(dest).getChannel();
...
voidcopyFile(File source, File destination)
copy File
try {
    FileInputStream fileInputStream = new FileInputStream(source);
    FileOutputStream fileOutputStream = new FileOutputStream(destination);
    FileChannel fileInputChannel = fileInputStream.getChannel();
    FileChannel fileOutputChannel = fileOutputStream.getChannel();
    fileInputChannel.transferTo(0, fileInputChannel.size(), fileOutputChannel);
    fileInputChannel.close();
    fileOutputChannel.close();
...
voidcopyFile(File source, File destination)
Copies a file from source to destination
FileInputStream inputStream = new FileInputStream(source);
FileOutputStream outputStream = new FileOutputStream(destination);
FileChannel sourceChannel = inputStream.getChannel();
FileChannel targetChannel = outputStream.getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
sourceChannel.close();
targetChannel.close();
inputStream.close();
...
voidcopyFile(File source, File destination)
copy File
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
    inputChannel = new FileInputStream(source).getChannel();
    outputChannel = new FileOutputStream(destination).getChannel();
    final long bytesToCopy = inputChannel.size();
    final long bytesCopied = inputChannel.transferTo(0, bytesToCopy, outputChannel);
    if (bytesToCopy != bytesCopied) {
...
voidcopyFile(File source, File destination)
copy File
FileInputStream fis = new FileInputStream(source);
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(destination);
    FileChannel sourceChannel = fis.getChannel();
    FileChannel destinationChannel = fos.getChannel();
    sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
    destinationChannel.close();
...
voidcopyFile(File source, File destination)
Copies single file to new location borrowed from: http://www.crazysquirrel.com/computing/java/basics/java-file-and-directory-copying.jspx
FileChannel sourceChannel = new FileInputStream(source).getChannel();
FileChannel targetChannel = new FileOutputStream(destination).getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
sourceChannel.close();
targetChannel.close();
voidcopyFile(File source, File destination)
copy File
FileChannel sourceChannel = new FileInputStream(source).getChannel();
FileChannel targetChannel = new FileOutputStream(destination).getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
sourceChannel.close();
targetChannel.close();
voidcopyFile(File source, File destination)
Copies a file.
FileChannel srcChannel = new FileInputStream(source).getChannel();
FileChannel dstChannel = new FileOutputStream(destination).getChannel();
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
srcChannel.close();
dstChannel.close();