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

intappendFile(String file, String text)
append File
return appendFile(file, text, null);
voidappendFile(String fileContents, File toFile)
This method is to append the given contents into a file.
RandomAccessFile raf = null;
if (!toFile.exists()) {
    throw new FileNotFoundException(" The specified destination file does not exists "); 
} else {
    try {
        raf = new RandomAccessFile(toFile, "rw"); 
        raf.skipBytes((int) raf.length());
        raf.writeBytes(fileContents);
...
booleanappendFile(String fileName, byte[] data)
append File
FileOutputStream out = null;
try {
    out = new FileOutputStream(fileName, true);
    out.write(data);
    out.flush();
    out.close();
} catch (Exception e) {
    e.printStackTrace();
...
voidappendFile(String fileName, String content)
append File
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)));
out.println(content);
out.close();
voidappendFile(String filename, String text)
append File
FileWriter fw = null;
try {
    fw = new FileWriter(filename, true);
    fw.append(text);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
...
voidappendFile(String filename, String text)
append File
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filename, true)));
out.println(text);
out.close();
voidappendFile(String fileName, StringBuffer sb)
append File
FileWriter fileWritter = new FileWriter(fileName, true);
BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
bufferWritter.write(sb.toString());
bufferWritter.close();
booleanappendFile(String fullName, String text)
append File
try {
    newFile(fullName);
    FileWriter out = new FileWriter(fullName, true);
    out.write(text);
    out.close();
} catch (Exception e) {
    System.out.println("error occur when creating file");
    e.printStackTrace();
...
voidappendFile(String path, String content)
append File
File file = new File(path);
if (!file.exists()) {
    file.createNewFile();
FileOutputStream outputStream = new FileOutputStream(file, true);
outputStream.write(content.getBytes("utf-8"));
outputStream.close();
voidappendFile(String path, String sb)
append File
try {
    FileWriter fstream = new FileWriter(path, true);
    try (BufferedWriter out = new BufferedWriter(fstream)) {
        out.write(sb);
} catch (Exception e) {
    System.err.println("Error append file: ");
    System.err.println(path);
...