Java FileInputStream Copy copyFileToFile(File input, String outputPath, String exportName)

Here you can find the source of copyFileToFile(File input, String outputPath, String exportName)

Description

copy File To File

License

LGPL

Declaration

public static File copyFileToFile(File input, String outputPath,
            String exportName) 

Method Source Code

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

import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    public static File copyFileToFile(File input, String outputPath,
            String exportName) {/*from   w  ww  .  j av  a2  s. c om*/
        File file = new File(outputPath, exportName);
        try {
            DataOutputStream out = new DataOutputStream(
                    new BufferedOutputStream(new FileOutputStream(file)));
            // Transfer bytes from in to out
            FileInputStream is = new FileInputStream(input);
            byte[] buf = new byte[1024];
            int len;
            while ((len = is.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            is.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.err.println("Error Writing/Reading Streams.");
        }
        return file;
    }
}

Related

  1. copyFileToDir(File oldFile, File outputDir)
  2. copyFileToDir(File sourceFile, File destDir)
  3. copyFileToDir(String targetDir, String[] filePath)
  4. CopyFileToDirectory(String file_name, String from_directory, String to_directory)
  5. copyFileToFile(File file, File destFile, boolean overwrite)
  6. copyFileToOutputStream(File file, OutputStream stream)
  7. copyFileToOutputStream(String fileLocation, OutputStream os)
  8. copyFileToStream(File currentFile, OutputStream outputStream)
  9. copyFileToStream(File file, OutputStream stream)