Java FileInputStream Copy copyFile(final String from, final String to)

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

Description

Copy file 'from' to file 'to' If not successful, exception is thrown

License

Open Source License

Declaration

public static void copyFile(final String from, final String to) throws IOException 

Method Source Code

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

import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    /**/*from   ww w .  ja  v a  2  s  .co  m*/
     * Copy file 'from' to file 'to' If not successful, exception is thrown
     */
    public static void copyFile(final String from, final String to) throws IOException {
        byte[] daten = readFile(from);
        writeFile(to, daten);
    }

    public static byte[] readFile(final String fileNamePath) throws IOException {
        FileInputStream input = null;
        byte[] daten = null;
        try {
            input = new FileInputStream(fileNamePath);
            daten = new byte[input.available()];
            input.read(daten);
        } finally {
            if (input != null) {
                input.close();
            }
        }
        return daten;
    }

    public static void writeFile(final String fileNamePath, final byte[] daten) throws IOException {
        FileOutputStream output = null;
        try {
            output = new FileOutputStream(fileNamePath);
            output.write(daten);
        } finally {
            if (output != null) {
                output.close();
            }
        }
    }
}

Related

  1. copyFile(final File src, final File dest)
  2. copyFile(final File src, final File dst)
  3. copyFile(final File srcFile, final File destFile)
  4. copyFile(final File srcPath, final File dstPath)
  5. copyFile(final InputStream in, final File destFile)
  6. copyFile(final String sourceFile, final String destinationFile)
  7. copyFile(final String sourceFilePath, final String destFilePath)
  8. copyFile(final String sSource, final String sDest)
  9. copyFile(InputStream in, File dst)