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 aFromFile, String aToFilename)
copy File
File outdir = getFileDirOnly(new File(aToFilename));
outdir.mkdirs();
FileInputStream fis = new FileInputStream(aFromFile.getAbsolutePath());
FileChannel inChannel = fis.getChannel();
FileOutputStream fos = new FileOutputStream(aToFilename);
FileChannel outChannel = fos.getChannel();
try {
    inChannel.transferTo(0, inChannel.size(), outChannel);
...
booleancopyFile(File copyFrom, File copyTo)
copy File
if (!isLockingSupported()) {
    return copyFileNormal(copyFrom, copyTo);
} else {
    return copyFileLocking(copyFrom, copyTo);
voidcopyFile(File file, String destDir)
copy File
if (!isCanReadFile(file))
    throw new RuntimeException("The File can't read:" + file.getPath());
if (!isCanWriteDirectory(destDir))
    throw new RuntimeException("The Directory can't write:" + destDir);
FileChannel srcChannel = null;
FileChannel dstChannel = null;
try {
    srcChannel = new FileInputStream(file).getChannel();
...
voidcopyFile(File fileIn, File fileOut)
copy File
FileChannel sourceChannel = null;
FileChannel destinationChannel = null;
try {
    sourceChannel = new FileInputStream(fileIn).getChannel();
    destinationChannel = new FileOutputStream(fileOut).getChannel();
    sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
} finally {
    try {
...
booleancopyFile(File from, File to)
copy File
return copyFile(from, to, false);
FilecopyFile(File from, File to)
copy File
FileChannel inChannel = new FileInputStream(from).getChannel();
FileChannel outChannel = new FileOutputStream(to).getChannel();
try {
    inChannel.transferTo(0, inChannel.size(), outChannel);
} catch (IOException e) {
    throw e;
} finally {
    if (inChannel != null)
...
voidcopyFile(File from, File to)
copy File
FileChannel infc = null;
FileChannel outfc = null;
try {
    infc = new FileInputStream(from).getChannel();
    outfc = new FileOutputStream(to).getChannel();
    long transfered = infc.transferTo(0, from.length(), outfc);
    while (transfered < from.length()) {
        transfered = infc.transferTo(transfered, from.length(), outfc);
...
voidcopyFile(File from, File to)
copy File
if (!from.exists()) {
    throw new FileNotFoundException();
if (from.isDirectory() || to.isDirectory()) {
    throw new FileNotFoundException();
FileInputStream fi = null;
FileChannel in = null;
...
voidcopyFile(File from, File to, long fromoffset, long tooffset, long size)
copy File
FileInputStream fis = new FileInputStream(from);
RandomAccessFile raf = new RandomAccessFile(to, "rw");
fis.skip(fromoffset);
raf.seek(tooffset);
byte buffer[] = new byte[1024];
long xfered = 0;
while (xfered < size) {
    int xln = fis.read(buffer, 0, (int) Math.min(buffer.length, size - xfered));
...
voidcopyFile(File in, File out)
Copy file from one destination to another.
try (FileInputStream fin = new FileInputStream(in);
        FileChannel inChannel = fin.getChannel();
        FileOutputStream fos = new FileOutputStream(out);
        FileChannel outChannel = fos.getChannel()) {
    inChannel.transferTo(0, inChannel.size(), outChannel);