Interface Copyable
public interface Copyable
Interface for copying files or directories
-
Method Summary
Modifier and TypeMethodDescriptiondefault 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 directorydefault boolean
Copies the given source file to the destination directorydefault boolean
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
newBackupOf
(Path path) Creates a backup file with ".bak" extension in the same directory as the original path.
-
Method Details
-
copyDirectory
Copies the given source directory to the destination directory- Parameters:
source
- The source directorydestination
- 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
default boolean copyDirectory(File source, File destination) throws FileIsSecurityRestrictedException, IOException, FileIsADirectoryException, FileIsNotADirectoryException, DirectoryAlreadyExistsException 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
Copies the given source file to the destination directory- Parameters:
source
- The source filedestination
- 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 copieddestination
- the destinationsourceEncoding
- the source encodingdestinationEncoding
- the destination encodinglastModified
- 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
Copies the given source file to the destination directory path.- Parameters:
source
- The source pathdestination
- 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
Copies multiple files to the destination directory.- Parameters:
sources
- List of source paths to copydestination
- The destination path- Throws:
IOException
- if an I/O error occurs during the copy
-
newBackupOf
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
-