Copying from a File to an Output Stream - Java File Path IO

Java examples for File Path IO:File Stream

Description

Copying from a File to an Output Stream

Demo Code

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;

public class Main {
  public static void main(String[] args) throws Exception {
    Path copy_from = Paths.get("C:/folder1/folder0/folder9",
        "draw_template.txt");
    Path copy_to = Paths.get("C:/folder1/folder0/folder8",
        "draw_template.txt");

    try (OutputStream os = new FileOutputStream(copy_to.toFile())) {
      Files.copy(copy_from, os);//from  w ww.j a v a  2 s .  c  o m
    } catch (IOException e) {
      System.err.println(e);
    }
  }
}

Result


Related Tutorials