public interface Erasable
Interface for delete files or directories
  • Method Summary

    Modifier and Type
    Method
    Description
    default Exception
    Checks if the File is a directory, exists, and is accessible
    default boolean
    delete(File file)
    Tries to delete the specified file or directory recursively if it is a directory
    default void
    Tries to delete all given files in the collection.
    default void
    Deletes the File and if it is a directory it deletes its sub-directories recursively.
    default void
    Deletes all files and directories recursively within the specified directory
    default void
    deleteAllFilesWithPrefix(File sourceDir, String prefix)
    Tries to delete all files that match the given prefix from the given source directory.
    default void
    deleteAllFilesWithSuffix(File directory, String theSuffix)
    Deletes all files with the given suffix recursively.
    default void
    deleteFile(File fileToDelete)
    Attempts to delete a specific file
    default void
    Tries to delete all files in the Directory.
    default void
    deleteFilesWithFileFilter(File sourceDir, FileFilter includeFileFilter)
    Tries to delete all files that match the given includeFileFilter from the given source directory.
    default void
    deleteFilesWithFilenameFilter(File source, FilenameFilter includeFilenameFilter)
    Tries to delete all files that match the given includeFilenameFilter from the given source directory.
  • Method Details

    • checkFile

      default Exception checkFile(File file)
      Checks if the File is a directory, exists, and is accessible
      Parameters:
      file - The File to check
      Returns:
      Null if all checks pass; otherwise, an appropriate Exception
    • delete

      default void delete(Collection<File> files) throws IOException
      Tries to delete all given files in the collection. Caution: This can not be undone.
      Parameters:
      files - The files to delete
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • delete

      default boolean delete(File file) throws IOException
      Tries to delete the specified file or directory recursively if it is a directory
      Parameters:
      file - The file or directory to delete
      Returns:
      true if deletion is successful; false otherwise
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • deleteAllFiles

      default void deleteAllFiles(Path dirPath) throws IOException
      Deletes all files and directories recursively within the specified directory
      Parameters:
      dirPath - The path of the directory to delete files within
      Throws:
      IOException - if an I/O exception occurs
    • deleteAllFiles

      default void deleteAllFiles(File file) throws IOException
      Deletes the File and if it is a directory it deletes its sub-directories recursively.
      Parameters:
      file - The File to delete.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • deleteAllFilesWithSuffix

      default void deleteAllFilesWithSuffix(File directory, String theSuffix) throws IOException
      Deletes all files with the given suffix recursively.
      Parameters:
      directory - The directory from where to delete the files with the given suffix.
      theSuffix - The suffix from the files to delete.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • deleteFile

      default void deleteFile(File fileToDelete) throws IOException
      Attempts to delete a specific file
      Parameters:
      fileToDelete - The file to delete
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • deleteFiles

      default void deleteFiles(File file) throws IOException
      Tries to delete all files in the Directory.
      Parameters:
      file - The Directory to delete files.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • deleteFilesWithFileFilter

      default void deleteFilesWithFileFilter(File sourceDir, FileFilter includeFileFilter) throws FileIsNotADirectoryException, IOException, FileIsSecurityRestrictedException
      Tries to delete all files that match the given includeFileFilter from the given source directory.
      Parameters:
      sourceDir - The source directory.
      includeFileFilter - The FileFilter for the files to be deleted. If null all files will be deleted.
      Throws:
      FileIsNotADirectoryException - If the destination file is a directory.
      IOException - If an error occurs by reading or writing.
      FileIsSecurityRestrictedException - If the source file is security restricted.
    • deleteAllFilesWithPrefix

      default void deleteAllFilesWithPrefix(File sourceDir, String prefix) throws FileIsNotADirectoryException, FileIsSecurityRestrictedException, IOException
      Tries to delete all files that match the given prefix from the given source directory.
      Parameters:
      sourceDir - The source directory
      prefix - The prefix from the files to delete
      Throws:
      FileIsNotADirectoryException - If the destination file is a directory.
      IOException - If an error occurs by reading or writing.
      FileIsSecurityRestrictedException - If the source file is security restricted.
    • deleteFilesWithFilenameFilter

      default void deleteFilesWithFilenameFilter(File source, FilenameFilter includeFilenameFilter) throws FileIsNotADirectoryException, IOException, FileIsSecurityRestrictedException
      Tries to delete all files that match the given includeFilenameFilter from the given source directory.
      Parameters:
      source - The source directory.
      includeFilenameFilter - The FilenameFilter for the files to be deleted. If null all files will be deleted.
      Throws:
      FileIsNotADirectoryException - If the destination file is a directory.
      IOException - If an error occurs by reading or writing.
      FileIsSecurityRestrictedException - If the source file is security restricted.