If you have to operate on files and cannot afford to loose data, seriously consider using one of the available frameworks. If you search the net, you come a cross some. One of the best is the Apache commons-transactions package. And of course it is probably better then any custom mechanism you can come up with.
Found this blogpost about using commons-transactions today. It is a step by step description about installation and ussage. Give it a try!