With the transaction started, you can begin file manipulation. You can perform following operations:
In our example, we’ll demo createResource and writeResource
4. Modify Resources
5. Transaction Management
If you have to operate on files and cannot afford to loose data, seriously consider using commons-transactions package.
It is probably better then any custom mechanism you can come up with. It supports 2 phase commit.
With a little work, you could probably make it into an XA compliant resource.
Aimed at providing lightweight, standardized, well tested and efficient implementations of utility classes commonly used in transactional Java programming. Initially there were implementations for multi level locks, transactional collections and transactional file access. The 1.x component is compatible to JDK1.2.
Commons IO is a library of utilities to assist with developing IO functionality.
The Lang Component provides a host of helper utilities for the java.lang API, notably String manipulation methods, basic numerical methods, object reflection, creation and serialization, and System properties.
log4j is a Java-based logging utility. It was originally written by Ceki Gülcü and is now a project of the Apache Software Foundation. It is used primarily as a debugging tool.