Java BufferedInputStream Copy copyFile(File srcFile, File detFolder)

Here you can find the source of copyFile(File srcFile, File detFolder)

Description

copy File

License

Apache License

Declaration

public static void copyFile(File srcFile, File detFolder) 

Method Source Code


//package com.java2s;
/*//from  www  .  j av  a 2 s.c o  m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

import java.io.File;

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

public class Main {
    public static void copyFile(File srcFile, File detFolder) {
        BufferedInputStream bin = null;
        BufferedOutputStream bout = null;
        try {
            String fileName = srcFile.getName();
            String targetFileName = detFolder.getAbsolutePath() + File.separatorChar + fileName;
            bin = new BufferedInputStream(new FileInputStream(srcFile));
            bout = new BufferedOutputStream(new FileOutputStream(new File(targetFileName)));
            byte[] buffer = new byte[1024];
            int count = 0;
            while ((count = bin.read(buffer, 0, 1024)) != -1) {
                bout.write(buffer, 0, count);
            }
            bout.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (bin != null)
                    bin.close();
                if (bout != null)
                    bout.close();
            } catch (Exception e) {

            }
        }
    }
}

Related

  1. copyFile(File src, File dst)
  2. copyFile(File src, File target)
  3. copyFile(File src, File targetDir, boolean onlyNew)
  4. copyFile(File src, String target)
  5. copyFile(File srcFile, File destFile, boolean createCopy)
  6. copyFile(File srcFile, File targetFolder)
  7. copyFile(final File from, final File to)
  8. copyFile(final File fSource, final File fDest)
  9. copyFile(final File source, final File dest, final boolean overwrite)