Here you can find the source of copy(File source, File target)
Parameter | Description |
---|---|
source | The source file |
target | The target file |
Parameter | Description |
---|---|
IOException | If the source file cannot be read or the target filecannot be written |
public static void copy(File source, File target) throws IOException
//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); }); } } }