Java FileInputStream Copy copyFile(String resourceFimeName, String targetFileName)

Here you can find the source of copyFile(String resourceFimeName, String targetFileName)

Description

copy File

License

Apache License

Declaration

public static boolean copyFile(String resourceFimeName, String targetFileName) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {

    public static boolean copyFile(String resourceFimeName, String targetFileName) throws IOException {

        return copyFile(new File(resourceFimeName), new File(targetFileName));
    }/* w w w  .j  av a  2 s  .com*/

    public static boolean copyFile(String resourceFimeName, File targetFile) throws IOException {
        return copyFile(new File(resourceFimeName), targetFile);
    }

    public static boolean copyFile(File resourceFile, String targetFileName) throws IOException {
        return copyFile(resourceFile, new File(targetFileName));
    }

    public static boolean copyFile(File resourceFile, File targetFile) throws IOException {
        if (resourceFile == null || targetFile == null)
            return false;

        if (resourceFile.exists()) {
            if (!targetFile.exists()) {
                File parentFile = targetFile.getParentFile();
                if (!parentFile.exists())
                    parentFile.mkdirs();
                targetFile.createNewFile();
            }
            FileInputStream in = new FileInputStream(resourceFile);
            FileOutputStream out = new FileOutputStream(targetFile);
            byte[] buffer = new byte[1024 * 8];
            int i = 0;

            while ((i = in.read(buffer)) != -1) {
                out.write(buffer, 0, i);
            }
            out.flush();
            in.close();
            out.close();
            return true;

        } else {
            return false;
        }
    }
}

Related

  1. copyFile(String oldPathFile, String newPathFile)
  2. copyFile(String original, String copy)
  3. copyFile(String pathOld, String pathNew)
  4. copyFile(String pathOrig, String pathDst)
  5. copyFile(String quelle, String ziel)
  6. copyFile(String s, String s1)
  7. copyFile(String source, String dest)
  8. copyFile(String source, String destination)
  9. copyFile(String source, String destination)