Java Path Copy nio write(InputStream in, Path path, StandardCopyOption op)

Here you can find the source of write(InputStream in, Path path, StandardCopyOption op)

Description

write.

License

Open Source License

Parameter

Parameter Description
in a java.io.InputStream object.
path a java.nio.file.Path object.
op a java.nio.file.StandardCopyOption object.

Declaration

public static void write(InputStream in, Path path, StandardCopyOption op) 

Method Source Code


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

import java.io.*;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

public class Main {
    /**//from   ww w. j  a v a 2s .  c o m
     * <p>write.</p>
     *
     * @param in   a {@link java.io.InputStream} object.
     * @param path a {@link java.nio.file.Path} object.
     */
    public static void write(InputStream in, Path path) {
        write(in, path, StandardCopyOption.REPLACE_EXISTING);
    }

    /**
     * <p>write.</p>
     *
     * @param in a {@link java.io.InputStream} object.
     * @param file a {@link java.io.File} object.
     */
    public static void write(InputStream in, File file) {
        write(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
    }

    /**
     * <p>write.</p>
     *
     * @param in a {@link java.io.InputStream} object.
     * @param path a {@link java.nio.file.Path} object.
     * @param op a {@link java.nio.file.StandardCopyOption} object.
     */
    public static void write(InputStream in, Path path, StandardCopyOption op) {
        try {
            Files.copy(in, path, op);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. createDirectory(Path parent, String name)
  2. createDirectoryIfNotExists(Path path)
  3. createDirectoryRecursively(Path dir)
  4. createDirectoryRecursively(String dirName)
  5. renameTo(Path from, Path to, CopyOption... options)