Java Path Copy nio copyFile(Path from, Path to)

Here you can find the source of copyFile(Path from, Path to)

Description

Copy file

License

Open Source License

Declaration

public static void copyFile(Path from, Path to) 

Method Source Code

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

import java.io.IOException;

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

public class Main {
    /** Copy file */
    public static void copyFile(Path from, Path to) {
        try {/*from   w  w  w.j  a  v a2 s .  co  m*/
            to.getParent().toFile().mkdirs();
            Files.copy(from, to);
        } catch (FileAlreadyExistsException e) {
        } catch (IOException e) {
            fatal("An error occured while writing " + to.toString(), e);
            return;
        }
    }

    /** Print fatal error and exit. */
    public static <T> T fatal(String message, Exception e) {
        System.out.println(message);
        if (e != null && System.getProperty("stacktrace") != null)
            e.printStackTrace();
        System.exit(0);
        return (T) null;
    }
}

Related

  1. copyContainer(String from, String to, IProgressMonitor monitor)
  2. copyContents(Path from, Path to)
  3. copyEverythingExcept(Path file, Path srcDir, Path dstDir, Predicate excluded, Consumer onCopy)
  4. copyFile(final String fileName, final String from, final String to)
  5. copyFile(InputStream from, Path to)
  6. copyFile(Path source, Path destination)
  7. copyFile(Path source, Path destination, CopyOption... options)
  8. copyFile(Path source, Path target)
  9. copyFile(Path source, Path target)