public interface Copyable
Interface for copying files or directories
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    copyDirectory(File source, File destination)
    Copies the given source directory to the given destination directory.
    default boolean
    copyDirectory(Path source, Path destination)
    Copies the given source directory to the destination directory
    default boolean
    copyFile(File source, File destination)
    Copies the given source file to the destination directory
    default boolean
    copyFile(Path source, Path destination)
    Copies the given source file to the destination directory path.
    default void
    copyFiles(Collection<File> sources, File destination, Charset sourceEncoding, Charset destinationEncoding, boolean lastModified)
    Copies the given source file to the given destination file with the given source encodings and destination encodings.
    default void
    copyFiles(Collection<Path> sources, Path destination)
    Copies multiple files to the destination directory.
    default File
    newBackupOf(File file, Charset sourceEncoding, Charset destinationEncoding)
    Creates a backup file in the same directory with the same name of the given file and with the extension of '*.bak'.
    default Path
    Creates a backup file with ".bak" extension in the same directory as the original path.
  • Method Details

    • copyDirectory

      default boolean copyDirectory(Path source, Path destination) throws IOException
      Copies the given source directory to the destination directory
      Parameters:
      source - The source directory
      destination - The destination directory
      Returns:
      true if the directory was successfully copied, otherwise false
      Throws:
      IOException - if an I/O error occurs during the copy
    • copyDirectory

      Copies the given source directory to the given destination directory.
      Parameters:
      source - The source directory.
      destination - The destination directory.
      Returns:
      's true if the directory is copied, otherwise false.
      Throws:
      FileIsSecurityRestrictedException - Is thrown if the source file is security restricted.
      IOException - Is thrown if an error occurs by reading or writing.
      FileIsADirectoryException - Is thrown if the destination file is a directory.
      FileIsNotADirectoryException - Is thrown if the source file is not a directory.
      DirectoryAlreadyExistsException - Is thrown if the directory already exists.
    • copyFile

      default boolean copyFile(File source, File destination) throws IOException
      Copies the given source file to the destination directory
      Parameters:
      source - The source file
      destination - The destination directory
      Returns:
      true if the file was successfully copied, otherwise false
      Throws:
      IOException - if an I/O error occurs during the copy
    • copyFiles

      default void copyFiles(Collection<File> sources, File destination, Charset sourceEncoding, Charset destinationEncoding, boolean lastModified)
      Copies the given source file to the given destination file with the given source encodings and destination encodings.
      Parameters:
      sources - the files the have to be copied
      destination - the destination
      sourceEncoding - the source encoding
      destinationEncoding - the destination encoding
      lastModified - if true, the last modified flag is set
    • newBackupOf

      default File newBackupOf(File file, Charset sourceEncoding, Charset destinationEncoding) throws IOException
      Creates a backup file in the same directory with the same name of the given file and with the extension of '*.bak'.
      Parameters:
      file - the file to backup.
      sourceEncoding - the source encoding of the file to backup.
      destinationEncoding - the destination encoding of the backup file. This can be null.
      Returns:
      the created backup file.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • copyFile

      default boolean copyFile(Path source, Path destination) throws IOException
      Copies the given source file to the destination directory path.
      Parameters:
      source - The source path
      destination - The destination directory path
      Returns:
      true if the file was successfully copied, otherwise false
      Throws:
      IOException - if an I/O error occurs during the copy
    • copyFiles

      default void copyFiles(Collection<Path> sources, Path destination) throws IOException
      Copies multiple files to the destination directory.
      Parameters:
      sources - List of source paths to copy
      destination - The destination path
      Throws:
      IOException - if an I/O error occurs during the copy
    • newBackupOf

      default Path newBackupOf(Path path) throws IOException
      Creates a backup file with ".bak" extension in the same directory as the original path.
      Parameters:
      path - The path to back up
      Returns:
      the path to the backup file
      Throws:
      IOException - if an I/O error occurs during the copy