Class FileOperations

java.lang.Object
com.helger.commons.io.file.FileOperations

@ThreadSafe public final class FileOperations extends Object
Wraps file operations.
Author:
Philip Helger
  • Field Details

    • DEFAULT_EXCEPTION_ON_DELETE_ROOT

      public static final boolean DEFAULT_EXCEPTION_ON_DELETE_ROOT
      The default value for warning if we're about to delete the root directory.
      See Also:
  • Method Details

    • isExceptionOnDeleteRoot

      public static boolean isExceptionOnDeleteRoot()
    • setExceptionOnDeleteRoot

      public static void setExceptionOnDeleteRoot(boolean bExceptionOnDeleteRoot)
    • createDir

      @Nonnull public static FileIOError createDir(@Nonnull File aDir)
      Create a new directory. The direct parent directory already needs to exist.
      Parameters:
      aDir - The directory to be created. May not be null.
      Returns:
      A non-null error code.
    • createDirIfNotExisting

      @Nonnull public static FileIOError createDirIfNotExisting(@Nonnull File aDir)
      Create a new directory if it does not exist. The direct parent directory already needs to exist.
      Parameters:
      aDir - The directory to be created if it does not exist. May not be null.
      Returns:
      A non-null error code.
    • createDirRecursive

      @Nonnull public static FileIOError createDirRecursive(@Nonnull File aDir)
      Create a new directory. The parent directories are created if they are missing.
      Parameters:
      aDir - The directory to be created. May not be null.
      Returns:
      A non-null error code.
    • createDirRecursiveIfNotExisting

      @Nonnull public static FileIOError createDirRecursiveIfNotExisting(@Nonnull File aDir)
      Create a new directory if it does not exist. The direct parent directory already needs to exist.
      Parameters:
      aDir - The directory to be created if it does not exist. May not be null.
      Returns:
      A non-null error code.
      See Also:
    • deleteDir

      @Nonnull public static FileIOError deleteDir(@Nonnull File aDir)
      Delete an existing directory. The directory needs to be empty before it can be deleted.
      Parameters:
      aDir - The directory to be deleted. May not be null.
      Returns:
      A non-null error code.
    • deleteDirIfExisting

      @Nonnull public static FileIOError deleteDirIfExisting(@Nonnull File aDir)
      Delete an existing directory if it is existing. The directory needs to be empty before it can be deleted.
      Parameters:
      aDir - The directory to be deleted. May not be null.
      Returns:
      A non-null error code.
      See Also:
    • deleteDirRecursive

      @Nonnull public static FileIOError deleteDirRecursive(@Nonnull File aDir)
      Delete an existing directory including all child objects.
      Parameters:
      aDir - The directory to be deleted. May not be null.
      Returns:
      A non-null error code.
    • deleteDirRecursiveIfExisting

      @Nonnull public static FileIOError deleteDirRecursiveIfExisting(@Nonnull File aDir)
      Delete an existing directory including all child objects if it is existing.
      Parameters:
      aDir - The directory to be deleted. May not be null.
      Returns:
      A non-null error code.
    • deleteFile

      @Nonnull public static FileIOError deleteFile(@Nonnull File aFile)
      Delete an existing file.
      Parameters:
      aFile - The file to be deleted. May not be null.
      Returns:
      A non-null error code.
    • deleteFileIfExisting

      @Nonnull public static FileIOError deleteFileIfExisting(@Nonnull File aFile)
      Delete a file if it is existing.
      Parameters:
      aFile - The file to be deleted. May not be null.
      Returns:
      A non-null error code.
    • renameFile

      @Nonnull public static FileIOError renameFile(@Nonnull File aSourceFile, @Nonnull File aTargetFile)
      Rename a file.
      Parameters:
      aSourceFile - The original file name. May not be null.
      aTargetFile - The destination file name. May not be null.
      Returns:
      A non-null error code.
    • renameDir

      @Nonnull public static FileIOError renameDir(@Nonnull File aSourceDir, @Nonnull File aTargetDir)
      Rename a directory.
      Parameters:
      aSourceDir - The original directory name. May not be null.
      aTargetDir - The destination directory name. May not be null.
      Returns:
      A non-null error code.
    • copyFile

      @Nonnull public static FileIOError copyFile(@Nonnull File aSourceFile, @Nonnull File aTargetFile)
      Copies the source file to the target file.
      Parameters:
      aSourceFile - The source file to use. May not be null. Needs to be an existing file.
      aTargetFile - The destination files. May not be null and may not be an existing file.
      Returns:
      A non-null error code.
    • copyDirRecursive

      @Nonnull public static FileIOError copyDirRecursive(@Nonnull File aSourceDir, @Nonnull File aTargetDir)
      Copy a directory including all child objects.
      Parameters:
      aSourceDir - The source directory to be copied. May not be null.
      aTargetDir - The destination directory where to be copied. This directory may not be existing. May not be null.
      Returns:
      A non-null error code.