file.delete() should be called outside the try block, otherwise the FileWriter associated with it won´t release the lock