I write code to delete a file, just like:
File logFile = new File(fileName);
deleteSuccess = logFile.delete();
But the Veracode: give me some warning about the resource is not released. I want to know how to release the resource after delete a file.
The Veracode error is like follows
Veracode:
Description
The application fails to release (or incorrectly releases) a system resource before it is made available for re-use. This condition often occurs with resources such as database connections or file handles. Most unreleased resource issues result in general software reliability problems, but if an attacker can intentionally trigger a resource leak, it may be possible to launch a denial of service attack by depleting the resource pool.
Recommendations When a resource is created or allocated, the developer is responsible for properly releasing the resource as well as accounting for all potential paths of expiration or invalidation. Ensure that all code paths properly release resources.