Class LockableFileWriter

java.lang.Object
java.io.Writer
org.apache.commons.io.output.LockableFileWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class LockableFileWriter extends Writer
FileWriter that will create and honor lock files to allow simple cross thread file lock handling.

This class provides a simple alternative to FileWriter that will use a lock file to prevent duplicate writes.

Note: The lock file is deleted when close() is called - or if the main file cannot be opened initially. In the (unlikely) event that the lock file cannot be deleted, an exception is thrown.

By default, the file will be overwritten, but this may be changed to append. The lock directory may be specified, but defaults to the system property java.io.tmpdir. The encoding may also be specified, and defaults to the platform default.

To build an instance, use LockableFileWriter.Builder.

See Also: