Java Files.copy(Path source, OutputStream out)

Syntax

Files.copy(Path source, OutputStream out) has the following syntax.

public static long copy(Path source,  OutputStream out)   throws IOException

Example

In the following code shows how to use Files.copy(Path source, OutputStream out) method.


import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
// w  w  w  .  j  a  va2  s.  com
public class Main {

  public static void main(String[] args) {

    Path copy_from_4 = Paths.get("C:/tutorial/Java/JavaFX", "tutor.txt");
    Path copy_to_4 = Paths.get("C:/tutorial/Java/Swing", "tutor.txt");
    try (OutputStream os = new FileOutputStream(copy_to_4.toFile())) {

      Files.copy(copy_from_4, os);

    } catch (IOException e) {
      System.err.println(e);
    }

  }
}




















Home »
  Java Tutorial »
    java.nio.file »




DirectoryStream.Filter
Files
FileStore
FileSystem
FileVisitor
Path
Paths
WatchService