File Append

The following static methods can be used to easily append text to the end of a file. Different arguments allow a flexible call with path string or file object.

Path String

The path method expects for the first argument the file path as string.

public static void append(String path, String text, String charsetName) throws FileNotFoundException, IOException { append(new File(path), text, charsetName); }

File Object

The file method expects for the first argument the file path as file object. Call of the method write saves the text to the end of the file.

public static void append(File file, String text, String charsetName) throws FileNotFoundException, IOException { if (file.exists() == false) throw new FileNotFoundException("File does not exist! "+file); write(new FileOutputStream(file,true), text, charsetName); }

Call

append("test.txt", "test content", "utf-8"); append(file, "test content", "utf-8");

Resources

Johannes Hammoud File Append 22.08.2009

I Coding : Community about Java programing

Language German+-

Java JSF JavaScript HTML CSS NetBeans GlassFish MySQL

Imprint

Visits
5744511
Today
80