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

voidcopyFileUsingChannel(File source, File dest)
copy File Using Channel
FileInputStream sourceStream = new FileInputStream(source);
FileChannel sourceChannel = sourceStream.getChannel();
FileOutputStream outputStream = new FileOutputStream(dest);
outputStream.getChannel().transferFrom(sourceChannel, 0, sourceChannel.size());
voidcopyFileUsingFileChannels(File source, File dest)
copy File Using File Channels
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();
...
voidcopyFileUsingFileChannels(File source, File dest)
Copy a file
FileInputStream inputStream = null;
FileOutputStream outputStream = null;
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
    inputStream = new FileInputStream(source);
    outputStream = new FileOutputStream(dest);
    if (inputStream != null)
...
voidcopyFileUsingFileChannels(File source, File dest)
copy File Using File Channels
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
    inputChannel = new FileInputStream(source).getChannel();
    outputChannel = new FileOutputStream(dest).getChannel();
    outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} catch (Exception e) {
    e.printStackTrace();
...
voidcopyFolder(File fin, File fout)
copy Folder
fout.mkdirs();
String[] children = fin.list();
if (children == null) {
} else {
    for (int p = 0; p < children.length; p++) {
        File f = new File(fin + "/" + children[p]);
        File f1 = new File(fout + "/" + children[p]);
        if (f.isDirectory())
...
voidcopyFromZip(ZipFile zipFile, String locationInBundle, File destination)
copy From Zip
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
    ZipEntry zipEntry = entries.nextElement();
    if (zipEntry.getName().startsWith(locationInBundle)) {
        String path = zipEntry.getName().substring(locationInBundle.length());
        File file = new File(destination, path);
        if (!zipEntry.isDirectory()) {
            createFileFromZipFile(file, zipFile, zipEntry);
...
voidcopyInternal(FileInputStream in, FileOutputStream out)
copy Internal
FileChannel src = in.getChannel();
FileChannel dest = out.getChannel();
src.transferTo(0, src.size(), dest);
longcopyLarge(FileInputStream in, FileOutputStream out)
Copies bytes from a large (over 2GB) FileInputStream to a FileOutputStream.
final FileChannel inc = in.getChannel();
return inc.transferTo(0L, inc.size(), out.getChannel());
voidcopyNio(final File source_file, final File destination_file)
copy Nio
if (!source_file.exists()) {
    return;
final File parTo = destination_file.getParentFile();
if (!parTo.exists()) {
    parTo.mkdirs();
if (!destination_file.exists()) {
...
voidcopyRec(File src, File dst)
Copies a directory or a file from source to destination.
if (src == null || dst == null)
    return;
if (dst.isFile())
    return;
if (src.isFile()) {
    copyFileToDir(src, dst);
} else {
    String name = src.getName();
...