Java File Copy nio fileCopy(File source, File target)

Here you can find the source of fileCopy(File source, File target)

Description

file Copy

License

LGPL

Declaration

public static void fileCopy(File source, File target) throws IOException 

Method Source Code


//package com.java2s;
/*//w ww  .java  2s  .c  o m
 * jesadido-poc
 * Copyright (C) 2016 Stefan K. Baur
 *
 * Licensed under the GNU Lesser General Public License, Version 3.0 (LGPL-3.0)
 * https://www.gnu.org/licenses/lgpl-3.0.txt
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

public class Main {
    public static void fileCopy(File source, File target) throws IOException {
        if (!target.getParentFile().exists()) {
            target.getParentFile().mkdirs();
        }
        Files.copy(new FileInputStream(source.getAbsolutePath().replace("%20", " ")), target.toPath(),
                StandardCopyOption.REPLACE_EXISTING);
    }
}

Related

  1. copyFileByMapped(String sourcePath, String targetPath)
  2. copyToFile(final InputStream is, final File file)
  3. copyToTempFile(final InputStream is, final String prefix, final String suffix)
  4. copyToTmpFile(InputStream in, String prefix, String suffix)
  5. fileCopy(File source, File destination)
  6. fileCopy(File sourceFile, File destFile)
  7. fileCopy(File src, File dest)
  8. fileCopy(final File dest, final File src)