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(String sourceFileName, String destinationFileName)
copy File
copyFile(new File(sourceFileName), new File(destinationFileName));
booleancopyFile(String src, String dest)
copy File
return copyFile(new File(src), new File(dest));
voidcopyFile(String srcFileName, String desFileName)
copy File
try {
    FileChannel srcChannel = new FileInputStream(srcFileName).getChannel();
    FileChannel dstChannel = new FileOutputStream(desFileName).getChannel();
    dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
    srcChannel.close();
    dstChannel.close();
} catch (IOException e) {
    e.printStackTrace();
...
booleancopyFile(String srcPath, String destPath)
copy File
boolean success = false;
FileChannel srcChannel = null;
FileChannel destChannel = null;
try {
    File dest = new File(destPath);
    if (dest.exists())
        dest.createNewFile();
    srcChannel = new FileInputStream(srcPath).getChannel();
...
voidcopyFileByChannel(String srcFileName, String dstFileName)
copy File By Channel
File srcFile = new File(srcFileName);
File dstFile = new File(dstFileName);
if (!srcFile.exists())
    throw new RuntimeException("src file not exists!");
if (dstFile.exists())
    throw new RuntimeException("dst file exists!");
FileChannel inFileChannel = null;
FileChannel outFileChannel = null;
...
booleancopyFileContent(final String sourcePath, final String targetPath)
copy File Content
FileInputStream fr = null;
FileOutputStream fw = null;
try {
    fr = new FileInputStream(sourcePath);
    fw = new FileOutputStream(targetPath);
    final FileChannel src = fr.getChannel();
    final FileChannel dest = fw.getChannel();
    dest.transferFrom(src, 0, src.size());
...
voidcopyFileIntoProjectFolder(String projectName, File file)
copy File Into Project Folder
FileChannel inChannel = null;
FileChannel outChannel = null;
List<File> libraryFiles = new ArrayList<File>();
FileInputStream istream = null;
FileOutputStream ostream = null;
try {
    File out = new File(Platform.getLocation() + File.separator + projectName + File.separator
            + File.separator + file.getName());
...
booleancopyFileLocking(File copyFrom, File copyTo)
copy File Locking
if ((!(copyFrom.exists())) || (copyTo == null)) {
    return false;
byte[] arrayOfByte = new byte[4096];
FileOutputStream fileOutput = new FileOutputStream(copyTo, true);
try {
    FileChannel channel = fileOutput.getChannel();
    FileLock fileLock = channel.tryLock();
...
voidcopyFileNIO(File src, File dest)
Copies the content of one file to another file.
if (!dest.exists()) {
    dest.createNewFile();
final FileChannel srcChannel = new FileInputStream(src).getChannel();
final FileChannel destChannel = new FileOutputStream(dest).getChannel();
final int bufferSize = (64 * 1024 * 1024);
final long size = srcChannel.size();
long position = 0;
...
booleancopyFileNio(File src, File dst)
Use NIO to copy a file
FileChannel srcChannel = null, dstChannel = null;
try {
    srcChannel = new FileInputStream(src).getChannel();
    dstChannel = new FileOutputStream(dst).getChannel();
        int safe_max = (64 * 1024 * 1024) / 4;
        long size = srcChannel.size();
        long position = 0;
...