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.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | FileDeleteStrategy.ForceFileDeleteStrategy
Force file deletion strategy. |
| Modifier and Type | Field and Description |
|---|---|
| public static final FileDeleteStrategy | FORCE
The singleton instance for forced file deletion, which always deletes, even if the file represents a non-empty directory. |
| private final String | name
The name of the strategy. |
| public static final FileDeleteStrategy | NORMAL
The singleton instance for normal file deletion, which does not permit the deletion of directories that are not empty. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public boolean | Returns: true if the file was deleted, or there was no such filethe file to delete, null returns true fileToDelete)Deletes the file object, which may be a file or a directory. |
| protected boolean | |
| public String | Returns: a string describing the delete strategyOverrides java. |
| FORCE | back to summary |
|---|---|
| public static final FileDeleteStrategy FORCE The singleton instance for forced file deletion, which always deletes, even if the file represents a non-empty directory. | |
| name | back to summary |
|---|---|
| private final String name The name of the strategy. | |
| NORMAL | back to summary |
|---|---|
| public static final FileDeleteStrategy NORMAL The singleton instance for normal file deletion, which does not permit the deletion of directories that are not empty. | |
| FileDeleteStrategy | back to summary |
|---|---|
| protected FileDeleteStrategy(String name) Restricted constructor.
| |
| delete | back to summary |
|---|---|
| public void delete(File fileToDelete) throws IOException Deletes 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
| |
| deleteQuietly | back to summary |
|---|---|
| public boolean deleteQuietly(File fileToDelete) Deletes the file object, which may be a file or a directory.
All
Subclass writers should override
| |
| doDelete | back to summary |
|---|---|
| protected boolean doDelete(File fileToDelete) throws IOException Actually 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
This implementation uses
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Gets a string describing the delete strategy.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | Returns: Always returnstruethe file to delete, not null fileToDelete)Overrides org. |
| ForceFileDeleteStrategy | back to summary |
|---|---|
| pack-priv ForceFileDeleteStrategy() Default Constructor | |
| doDelete | back to summary |
|---|---|
| protected boolean doDelete(File fileToDelete) throws IOException Overrides org. Deletes the file object.
This implementation uses the file to delete, not null
Always returns | |