Java BufferedInputStream Copy copyFile(String fileName, File sourceRoot, File targetRoot, Set copied)

Here you can find the source of copyFile(String fileName, File sourceRoot, File targetRoot, Set copied)

Description

copy File

License

Open Source License

Declaration

private static final void copyFile(String fileName, File sourceRoot, File targetRoot, Set copied)
            throws IOException 

Method Source Code

//package com.java2s;
/**/*from   w w w . j  a  v  a  2  s .  c  om*/
 * Create a the content for a readme file to accompany a configuration.
 * Basic configuration info, Jave and GoldenGATE version requirements, and
 * GoldenGATE software license are added automatically. A dialog allows for
 * entering a custom description text for the configuration, to be inserted
 * right below the basic info. This method returns the individual lines of
 * the readme file in an array of strings. If the dialog is cancelled, the
 * array is empty, but this method never returns null.
 * @param configName the name of the configuration to create a readme file
 *            for
 * @param timestamp the creation timestamp of the configuration
 * @return the lines of the readme file in an array of strings, or an empty
 *         array, if the input dialog was cancelled
 */

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

import java.io.File;

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

import java.io.IOException;
import java.io.InputStream;

import java.io.OutputStream;

import java.util.Set;

public class Main {
    private static final void copyFile(String fileName, File sourceRoot, File targetRoot, Set copied)
            throws IOException {

        //   open source file
        File sourceFile = new File(sourceRoot, fileName);
        InputStream source = new BufferedInputStream(new FileInputStream(sourceFile));

        //   create target file
        File targetFile = new File(targetRoot, fileName);
        targetFile.getParentFile().mkdirs();
        targetFile.createNewFile();

        //   open target file
        OutputStream target = new BufferedOutputStream(new FileOutputStream(targetFile));

        //   copy data
        int count;
        byte[] data = new byte[1204];
        while ((count = source.read(data, 0, data.length)) != -1)
            target.write(data, 0, count);
        source.close();
        target.flush();
        target.close();

        //   set modification data of copy
        targetFile.setLastModified(sourceFile.lastModified());
    }
}

Related

  1. copyFile(final File to, final File from)
  2. copyFile(InputStream is, File newFile)
  3. copyFile(InputStream src, File dest)
  4. copyFile(InputStream src, File dst)
  5. copyFile(String dest_path, String src_path)
  6. copyFile(String from, String to)
  7. copyFile(String fromFile, String toFile)
  8. copyFile(String source, String dest)
  9. copyFile(String source, String destination)