Java Utililty Methods File Append

List of utility methods to do File Append

Description

The list of methods to do File Append are organized into topic(s).

Method

voidappendFile(String source, String filetoappend)
append File
try {
    boolean append = true;
    File filesrc = new File(source);
    BufferedWriter output = new BufferedWriter(new FileWriter(filesrc, append));
    File ftoappend = new File(filetoappend);
    BufferedReader br = new BufferedReader(new FileReader(ftoappend));
    String line = br.readLine();
    while (line != null) {
...
booleanappendFile(String strThrift, String filePath)
append File
PrintWriter out = null;
try {
    out = new PrintWriter(new BufferedWriter(new FileWriter(filePath, true)));
    out.println(strThrift);
    out.flush();
    out.close();
} catch (IOException e) {
    return false;
...
booleanappendFileBytes(String srcFileName, String tarFileName)
append File Bytes
BufferedInputStream inBuff = null;
BufferedOutputStream outBuff = null;
try {
    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) {
...
voidappendFileContent(File file, String content, boolean append)
Appends content to given file.
Writer fw = null;
try {
    fw = new OutputStreamWriter(new FileOutputStream(file, append), "UTF-8");
    fw.append(content);
} finally {
    if (fw != null)
        fw.close();
booleanappendFileLines(String fileName, String[] data)
{ method
return appendFileLines(new File(fileName), data);
voidappendFilePart(File dstFile, byte[] bytes)
Helper method to append bytes to a specified file.
try (FileOutputStream outputStream = new FileOutputStream(dstFile, true);) {
    outputStream.write(bytes);
    outputStream.flush();
} catch (IOException e) {
    throw new RuntimeException(
            "Could not create and append the bytes to the file " + dstFile.getAbsolutePath()); 
AappendHex(A sb, byte[] array, int offset, int len, char sep)
append Hex
if (len <= 0) {
    return sb;
for (int curOffset = offset, maxOffset = offset + len; curOffset < maxOffset; curOffset++) {
    byte b = array[curOffset];
    if ((curOffset > offset) && (sep != EMPTY_HEX_SEPARATOR)) {
        sb.append(sep);
    sb.append(HEX_DIGITS.charAt((b >> 4) & 0x0F));
    sb.append(HEX_DIGITS.charAt(b & 0x0F));
return sb;
voidappendHexJavaScriptRepresentation(Appendable out, int codePoint)
Returns a javascript representation of the character in a hex escaped format.
if (Character.isSupplementaryCodePoint(codePoint)) {
    char[] surrogates = Character.toChars(codePoint);
    appendHexJavaScriptRepresentation(out, surrogates[0]);
    appendHexJavaScriptRepresentation(out, surrogates[1]);
    return;
out.append("\\u").append(HEX_CHARS[(codePoint >>> 12) & 0xf]).append(HEX_CHARS[(codePoint >>> 8) & 0xf])
        .append(HEX_CHARS[(codePoint >>> 4) & 0xf]).append(HEX_CHARS[codePoint & 0xf]);
...
voidappendHexJavaScriptRepresentation(StringBuilder sb, char c)
append Hex Java Script Representation
try {
    appendHexJavaScriptRepresentation(c, sb);
} catch (IOException ex) {
    throw new RuntimeException(ex);
voidappendTo(String fileName, String str)
Append a String to a file.
RandomAccessFile f = null;
if (str == null)
    return;
try {
    f = new RandomAccessFile(fileName, "rw");
    long length = f.length();
    f.seek(length);
    f.write(str.getBytes());
...