Files.copy(InputStream in, Path target, CopyOption ... options) has the following syntax.
public static long copy(InputStream in, Path target, CopyOption ... options) throws IOException
In the following code shows how to use Files.copy(InputStream in, Path target, CopyOption ... options) method.
/* www . j a v a2 s . c om*/ import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static void main(String[] args) { Path copy_from_2 = Paths.get("C:/tutorial/Java/JavaFX", "tutor.txt"); Path copy_to_2 = Paths.get("C:/tutorial/Java/Swing", "tutor.txt"); try (InputStream is = new FileInputStream(copy_from_2.toFile())) { Files.copy(is, copy_to_2, REPLACE_EXISTING); } catch (IOException e) { System.err.println(e); } } }
The code above generates the following result.