Java File Append appendFileBytes(String srcFileName, String tarFileName)

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

Description

append File Bytes

License

Open Source License

Declaration

public static boolean appendFileBytes(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 appendFileBytes(String srcFileName, String tarFileName) {
        BufferedInputStream inBuff = null;
        BufferedOutputStream outBuff = null;
        try {/*from   w  w  w.  j  ava2 s  . c o m*/
            inBuff = new BufferedInputStream(new FileInputStream(srcFileName));
            outBuff = new BufferedOutputStream(new FileOutputStream(tarFileName, true));

            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. appendFile(String fullName, String text)
  2. appendFile(String path, String content)
  3. appendFile(String path, String sb)
  4. appendFile(String source, String filetoappend)
  5. appendFile(String strThrift, String filePath)
  6. appendFileContent(File file, String content, boolean append)
  7. appendFileLines(String fileName, String[] data)
  8. appendFilePart(File dstFile, byte[] bytes)
  9. appendHex(A sb, byte[] array, int offset, int len, char sep)