Java Utililty Methods File Copy nio

List of utility methods to do File Copy nio

Description

The list of methods to do File Copy nio are organized into topic(s).

Method

voidcopy(File source, File destination)
Copies a file from source to destination.
FileInputStream in = new FileInputStream(source);
FileOutputStream out = new FileOutputStream(destination);
byte[] buffer = new byte[1024 * 16];
int len;
try {
    while ((len = in.read(buffer)) != -1)
        out.write(buffer, 0, len);
} finally {
...
voidcopy(File source, File destination)
copy
try {
    FileChannel sourceChannel = new FileInputStream(source.getPath()).getChannel();
    FileChannel destinationChannel = new FileOutputStream(destination.getPath()).getChannel();
    destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
    sourceChannel.close();
    destinationChannel.close();
} catch (Exception e) {
    System.err.println("Couldn't close sources or write");
...
voidcopy(File source, File destination)

Copys a file

FileChannel inChannel = new FileInputStream(source).getChannel();
FileChannel outChannel = new FileOutputStream(destination).getChannel();
inChannel.transferTo(0, inChannel.size(), outChannel);
voidcopy(File source, File destination)
copy
if (source.isDirectory()) {
    copyDirectory(source, destination);
} else {
    copyFile(source, destination);
longcopy(File source, File destination)
Copies file using nio transfer method.
logger.entering("de.axelwernicke.mypod.util.FileUtils", "copy");
long bytesCopied = -1;
try {
    boolean copied = false;
    int tries = 0;
    FileChannel fic = new FileInputStream(source).getChannel();
    FileChannel foc = new FileOutputStream(destination).getChannel();
    do {
...
voidcopy(File source, File target)
Copy one file to another
FileChannel input = null;
FileChannel output = null;
try {
    input = new FileInputStream(source).getChannel();
    output = new FileOutputStream(target).getChannel();
    MappedByteBuffer buffer = input.map(FileChannel.MapMode.READ_ONLY, 0, input.size());
    output.write(buffer);
} finally {
...
voidcopy(File source, File target)
copy
FileInputStream sourceOutStream = new FileInputStream(source);
FileOutputStream targetOutStream = new FileOutputStream(target);
FileChannel sourceChannel = sourceOutStream.getChannel();
FileChannel targetChannel = targetOutStream.getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
sourceChannel.close();
targetChannel.close();
sourceOutStream.close();
...
voidcopy(File source, File target)
Copies a file from a source location to a target location using system specific line endings
try (PrintWriter stream = new PrintWriter(new FileWriter(source, true))) {
    Files.lines(target.toPath()).forEach(s -> {
        stream.println(s);
    });
voidcopy(File source, File target, FilenameFilter filter)
Copy file or directory to the specified destination.
copy(source, target, filter, false, true);
voidcopy(File sourceFile, File destFile)
Copy a source file to a specified destination path.
if (!destFile.exists()) {
    destFile.createNewFile();
FileChannel source = null;
FileChannel destination = null;
try {
    source = new FileInputStream(sourceFile).getChannel();
    destination = new FileOutputStream(destFile).getChannel();
...