Package org.apache.commons.io
Class FileDeleteStrategy
java.lang.Object
org.apache.commons.io.FileDeleteStrategy
Strategy for deleting files.
 
There is more than one way to delete a file. You may want to limit access to certain directories, to only delete directories if they are empty, or maybe to force deletion.
This class captures the strategy to use and is designed for user subclassing.
- Since:
- 1.3
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final FileDeleteStrategyThe singleton instance for forced file deletion, which always deletes, even if the file represents a non-empty directory.static final FileDeleteStrategyThe singleton instance for normal file deletion, which does not permit the deletion of directories that are not empty.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidDeletes the file object, which may be a file or a directory.booleandeleteQuietly(File fileToDelete) Deletes the file object, which may be a file or a directory.protected booleanActually deletes the file object, which may be a file or a directory.toString()Gets a string describing the delete strategy.
- 
Field Details- 
NORMALThe singleton instance for normal file deletion, which does not permit the deletion of directories that are not empty.
- 
FORCEThe singleton instance for forced file deletion, which always deletes, even if the file represents a non-empty directory.
 
- 
- 
Constructor Details- 
FileDeleteStrategyRestricted constructor.- Parameters:
- name- the name by which the strategy is known
 
 
- 
- 
Method Details- 
deleteDeletes the file object, which may be a file or a directory. If the file does not exist, the method just returns.Subclass writers should override doDelete(File), not this method.- Parameters:
- fileToDelete- the file to delete, not null
- Throws:
- NullPointerException- if the file is null
- IOException- if an error occurs during file deletion
 
- 
deleteQuietlyDeletes the file object, which may be a file or a directory. AllIOExceptions are caught and false returned instead. If the file does not exist or is null, true is returned.Subclass writers should override doDelete(File), not this method.- Parameters:
- fileToDelete- the file to delete, null returns true
- Returns:
- true if the file was deleted, or there was no such file
 
- 
doDeleteActually deletes the file object, which may be a file or a directory.This method is designed for subclasses to override. The implementation may return either false or an IOExceptionwhen deletion fails. Thedelete(File)anddeleteQuietly(File)methods will handle either response appropriately. A check has been made to ensure that the file will exist.This implementation uses FileUtils.delete(File).- Parameters:
- file- the file to delete, exists, not null
- Returns:
- true if the file was deleted
- Throws:
- NullPointerException- if the file is null
- IOException- if an error occurs during file deletion
 
- 
toStringGets a string describing the delete strategy.
 
-