[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-commons-dev
Subject: [jira] [Commented] (IO-413) deleteQuietly(File) should try to closeOnDelete too
From: "Sebb (JIRA)" <jira () apache ! org>
Date: 2013-11-30 11:07:35
Message-ID: JIRA.12681953.1385790611511.48865.1385809655833 () arcas
[Download RAW message or body]
[ https://issues.apache.org/jira/browse/IO-413?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13835656#comment-13835656 \
]
Sebb commented on IO-413:
-------------------------
What does file.delete() return if the file does not exist? I suspect it returns \
false, so it would probably be better to check whether the file exists rather than \
relying on the return value.
> deleteQuietly(File) should try to closeOnDelete too
> ---------------------------------------------------
>
> Key: IO-413
> URL: https://issues.apache.org/jira/browse/IO-413
> Project: Commons IO
> Issue Type: Improvement
> Components: Utilities
> Reporter: BELUGA BEHR
> Priority: Minor
>
> Something like...
> {code}
> public static boolean deleteQuietly(final File file, final boolean deleteOnExit) {
> boolean fileDeleted = false;
> if (file == null) {
> return false;
> }
> try {
> if (file.isDirectory()) {
> cleanDirectory(file);
> }
> } catch (final Exception ignored) {
> }
> try {
> fileDeleted = file.delete();
> } catch (final Exception ignored) {
> return false;
> }
> if (deleteOnExit && !fileDeleted)
> {
> file.deleteOnExit();
> }
> return fileDeleted;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.1#6144)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic