This content has been marked as final. Show 6 replies
cenkbahtiyar wrote:That depends on what you want.
Should I do something like that "file.deleteOnExit()" if file exists, or what else?
The file is very likely to be unusable, if an IOException happens, so you might as well delete the file.
But that's unlikely to be the only thing that you'd want to do. If this is part of a file->save action, then you'd want to tell the user that saving failed, for example.
I just want the file be deleted if the write operation is not succeeded.
But i do not know internals, so in some kind of exceptions maybe it will not let me delete the file, even throw exception :)
Is deleting file with "delete()" method of file surely delete it, without throwing exception, or some other cases may arise?
But i do not know internals, so in some kind of exceptions maybe it will not let me delete the file, even throw exception :)Close the output stream and call File.delete(). It isn't specified to throw any exceptions - see the Javadoc. It returns a boolean telling you whether it succeeded. If it didn't succeed maybe calling File.deleteOnExit() might be a good idea.