Java BufferedInputStream Copy copyFileBytes(String srcFileName, String tarFileName)

Here you can find the source of copyFileBytes(String srcFileName, String tarFileName)

Description

copy File Bytes

License

Open Source License

Declaration

public static boolean copyFileBytes(String srcFileName, String tarFileName) 

Method Source Code


//package com.java2s;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

import java.io.FileInputStream;

import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
    public static boolean copyFileBytes(String srcFileName, String tarFileName) {
        BufferedInputStream inBuff = null;
        BufferedOutputStream outBuff = null;
        try {/*  ww w . j  av  a 2  s  . c  o  m*/
            inBuff = new BufferedInputStream(new FileInputStream(srcFileName));
            outBuff = new BufferedOutputStream(new FileOutputStream(tarFileName));

            byte[] b = new byte[1024 * 5];
            int len;
            while ((len = inBuff.read(b)) != -1) {
                outBuff.write(b, 0, len);
            }
            outBuff.flush();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        } finally {
            try {
                if (inBuff != null) {
                    inBuff.close();
                }
                if (outBuff != null) {
                    outBuff.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }
        return true;
    }
}

Related

  1. copyFile(String source, String dest)
  2. copyFile(String source, String destination)
  3. copyFile(String source, String destination)
  4. copyFile(String sourceFilePath, String destinationFilePath)
  5. copyFile(String src, String dest)
  6. copyFileFromStream(InputStream in, File dest)
  7. copyFileFromZipToDir(String zipFile, String fileNamePattern, File dir)
  8. copyFileNormal(File copyFrom, File copyTo)
  9. copyFileToFile(File in, File out)