Package io.github.astrapi69.file.copy
Class CopyFileExtensions
java.lang.Object
io.github.astrapi69.file.copy.CopyFileExtensions
The class
CopyFileExtensions
helps you to copy files.-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Copies the given source file to the given destination file.static boolean
Copies the given source file to the given destination file with the option to set the lastModified time from the given destination file.static boolean
copyFile
(File source, 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.static boolean
Copies the given source file to the destination filestatic 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.static void
copyFiles
(Collection<Path> sources, Path destination) Copies multiple files to the destination directorystatic boolean
copyFileToDirectory
(File source, File destinationDir) Copies the given source file to the given destination directory.static boolean
copyFileToDirectory
(File source, File destinationDir, boolean lastModified) Copies the given source file to the given destination directory with the option to set the lastModified time from the given destination directory.static 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'.static Path
newBackupOf
(Path file) Creates a backup file with ".bak" extension in the same directory as the original file
-
Method Details
-
copyFile
Copies the given source file to the destination file- Parameters:
source
- The source filedestination
- The destination file- 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 files to copydestination
- The destination directory- 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 file- Parameters:
file
- The file to back up- Returns:
- the path to the backup file
- Throws:
IOException
- if an I/O error occurs during the copy
-
copyFile
Copies the given source file to the given destination file.- Parameters:
source
- The source file.destination
- The destination file.- Returns:
- 's true if the file is copied, otherwise false.
- Throws:
IOException
- Is thrown if an error occurs by reading or writing.
-
copyFile
public static boolean copyFile(File source, File destination, boolean lastModified) throws IOException Copies the given source file to the given destination file with the option to set the lastModified time from the given destination file.- Parameters:
source
- The source file.destination
- The destination file.lastModified
- Flag the tells if the attribute lastModified has to be set with the attribute from the destination file.- Returns:
- 's true if the file is copied, otherwise false.
- Throws:
IOException
- Is thrown if an error occurs by reading or writing.
-
copyFile
public static boolean copyFile(File source, File destination, Charset sourceEncoding, Charset destinationEncoding, boolean lastModified) throws IOException Copies the given source file to the given destination file with the given source encodings and destination encodings.- Parameters:
source
- the sourcedestination
- the destinationsourceEncoding
- the source encodingdestinationEncoding
- the destination encodinglastModified
- if true the last modified flag is set.- Returns:
- true if the given file is copied otherwise false.
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
copyFiles
public static 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
-
copyFileToDirectory
public static boolean copyFileToDirectory(File source, File destinationDir) throws FileIsNotADirectoryException, IOException Copies the given source file to the given destination directory.- Parameters:
source
- The source file to copy in the destination directory.destinationDir
- The destination directory.- Returns:
- 's true if the file is copied to the destination directory, otherwise false.
- Throws:
FileIsNotADirectoryException
- Is thrown if the source file is not a directory.IOException
- Is thrown if an error occurs by reading or writing.
-
copyFileToDirectory
public static boolean copyFileToDirectory(File source, File destinationDir, boolean lastModified) throws FileIsNotADirectoryException, IOException Copies the given source file to the given destination directory with the option to set the lastModified time from the given destination directory.- Parameters:
source
- The source directory.destinationDir
- The destination directory.lastModified
- Flag the tells if the attribute lastModified has to be set with the attribute from the destination directory.- Returns:
- 's true if the file is copied to the given directory, otherwise false.
- Throws:
FileIsNotADirectoryException
- Is thrown if the source file is not a directory.IOException
- Is thrown if an error occurs by reading or writing.
-
newBackupOf
public static 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.
-