Java File Copy nio copy(File source, File target)

Here you can find the source of copy(File source, File target)

Description

Copies a file from a source location to a target location using system specific line endings

License

Open Source License

Parameter

Parameter Description
source The source file
target The target file

Exception

Parameter Description
IOException If the source file cannot be read or the target filecannot be written

Declaration

public static void copy(File source, File target) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import java.nio.file.Files;

public class Main {
    /**//from  w ww.  j a  va  2s. com
     * Copies a file from a source location to a target location using system
     * specific line endings
     * 
     * @param source The source file
     * @param target The target file
     * @throws IOException If the source file cannot be read or the target file
     *                     cannot be written
     */
    public static void copy(File source, File target) throws IOException {
        try (PrintWriter stream = new PrintWriter(new FileWriter(source, true))) {
            Files.lines(target.toPath()).forEach(s -> {
                stream.println(s);
            });
        }
    }
}

Related

  1. copy(File source, File destination)
  2. copy(File source, File destination)
  3. copy(File source, File destination)
  4. copy(File source, File target)
  5. copy(File source, File target)
  6. copy(File source, File target, FilenameFilter filter)
  7. copy(File sourceFile, File destFile)
  8. copy(File sourceFile, File destFile)
  9. copy(File sourceFile, File destinationFile)