Java File Copy fileCopy(File srcFile, File tarFile)

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

Description

file Copy

License

Apache License

Declaration

public static void fileCopy(File srcFile, File tarFile) throws Exception 

Method Source Code


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

import java.io.*;

public class Main {

    public static void fileCopy(File srcFile, File tarFile) throws Exception {
        FileInputStream is = null;
        FileOutputStream os = null;
        try {/*from  www  .  ja v  a  2s  .  c  om*/
            is = new FileInputStream(srcFile);
            os = new FileOutputStream(tarFile);
            // write the file to the file specified
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
        } finally {
            if (is != null) {
                is.close();
            }
            if (os != null) {
                os.close();
            }
        }
    }
}

Related

  1. copyFiles(String fromDirName, String toDirName)
  2. copyFileToPath(String fileToPath, String fileName, String sourceFile)
  3. doCopyFile(File srcFile, File destFile, boolean preserveFileDate)
  4. doCopyFile(File srcFile, File destFile, boolean preserveFileDate)
  5. fileCopy(File source, String dest)
  6. FileCopy(InputStream input, OutputStream output, int bufferSize)
  7. fileCopy(String from, String to)
  8. fileCopy(String from, String to)
  9. fileCopy(String fromPath, String toPath)