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 inName, String otName)
fast file copy utility function
File inFile = null;
File otFile = null;
try {
    inFile = new File(inName);
    otFile = new File(otName);
} catch (Exception e) {
    e.printStackTrace();
if (inFile == null || otFile == null)
    return;
FileChannel sourceChannel = new FileInputStream(inFile).getChannel();
FileChannel destinationChannel = new FileOutputStream(otFile).getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
sourceChannel.close();
destinationChannel.close();
voidcopyFile(String input, String output)
copies a file from input to output
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(input)));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output)));
String line = null;
while ((line = in.readLine()) != null) {
    out.write(line);
    out.newLine();
in.close();
...
voidcopyFile(String origPath, String destPath)
Convenience function to copy a file.
FileInputStream fis = null;
FileOutputStream fos = null;
try {
    fis = new FileInputStream(origPath);
    fos = new FileOutputStream(destPath);
    final FileChannel in = fis.getChannel();
    final FileChannel out = fos.getChannel();
    in.transferTo(0, in.size(), out);
...
voidcopyFile(String source, String destination)
copy File
File sourceFile = new File(source);
File destinationFile = new File(destination);
copyFile(sourceFile, destinationFile);
voidcopyFile(String source, String destination)
copy File
copyFile(new File(source), new File(destination));
voidcopyFile(String source, String destination)
This copies the given file to the given location (both names must be valid).
copyFile(new File(source), new File(destination));
voidcopyFile(String source, String target)
copy File
copyFile(new File(source), new File(target));
FilecopyFile(String source, String target)
Copies source file to target.
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
    inputChannel = new FileInputStream(source).getChannel();
    outputChannel = new FileOutputStream(target).getChannel();
    outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} finally {
    if (inputChannel != null) {
...
booleancopyFile(String sourceFile, String destFile)
Copies a file
java.io.File source = new java.io.File(sourceFile);
java.io.File dest = new java.io.File(destFile);
try {
    copyFile(source, dest);
    return true;
} catch (IOException e) {
    e.printStackTrace();
    return false;
...
voidcopyFile(String sourceFilename, String destFilename)
copy File
File sourceFile = new File(sourceFilename);
File destFile = new File(destFilename);
if (!sourceFile.exists()) {
    System.out.println("ERROR: Source file " + sourceFilename + " does not exist!");
    return;
try {
    if (!destFile.exists()) {
...