Java Path Copy nio copyFile(Path source, Path target, boolean foreign, CopyOption... options)

Here you can find the source of copyFile(Path source, Path target, boolean foreign, CopyOption... options)

Description

Copy a file to a local or foreign file system

License

Open Source License

Parameter

Parameter Description
source The source file path
target The target file path
foreign When true create a copy on the remote fiel system
options Copy options

Exception

Parameter Description
IOException an exception

Declaration

private static void copyFile(Path source, Path target, boolean foreign, CopyOption... options)
        throws IOException 

Method Source Code


//package com.java2s;
/*//from ww w .ja va  2  s  . c o m
 * Copyright (c) 2013-2017, Centre for Genomic Regulation (CRG).
 * Copyright (c) 2013-2017, Paolo Di Tommaso and the respective authors.
 *
 *   This file is part of 'Nextflow'.
 *
 *   Nextflow is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Nextflow is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Nextflow.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.IOException;
import java.io.InputStream;

import java.nio.file.CopyOption;

import java.nio.file.Files;

import java.nio.file.Path;

public class Main {
    /**
     * Copy a file to a local or foreign file system
     *
     * @param source The source file path
     * @param target The target file path
     * @param foreign When {@code true} create a copy on the remote fiel system
     * @param options Copy options
     * @throws IOException
     */
    private static void copyFile(Path source, Path target, boolean foreign, CopyOption... options)
            throws IOException {

        if (!foreign) {
            source.getFileSystem().provider().copy(source, target, options);
            return;
        }

        try (InputStream in = Files.newInputStream(source)) {
            Files.copy(in, target);
        }
    }
}

Related

  1. copyFile(Path from, Path to)
  2. copyFile(Path source, Path destination)
  3. copyFile(Path source, Path destination, CopyOption... options)
  4. copyFile(Path source, Path target)
  5. copyFile(Path source, Path target)
  6. copyFile(Path source, Path target, boolean okToOverwrite, boolean preserveAttributes)
  7. copyFile(Path source, Path target, boolean prompt, boolean preserve)
  8. copyFile(Path source, Path target, boolean prompt, boolean preserve)
  9. copyFile(Path source, Path target, boolean prompt, boolean preserve)