cenkbahtiyar wrote:That depends on what you want.
Should I do something like that "file.deleteOnExit()" if file exists, or what else?
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.