Is it possible to roll back the current IO operation incase of any exceptions during writing? I'm trying to write a UTF-8 string to a file with Okio library using the below expression
file.sink().buffer().writeUtf8(fileContent).close()
It works for normal cases. But if an exception occurs during writing, it just writes an empty string to a file overwriting the existing one.
I know I can backup the old content before writing and overwrite in the catch block incase of exceptions. But it looks like a common problem and I'm wondering if there are any alternative solutions available for the same.
Thanks!