Interface Renameable
public interface Renameable
Interface
Renameable
provides methods for renaming files and directories.-
Method Summary
Modifier and TypeMethodDescriptiondefault String
appendSystemTimeToFilename
(File fileToRename) Returns the filename from the given file with the system time appendeddefault String
appendSystemTimeToFilename
(File fileToRename, Date add2Name) Returns the filename from the given file with the specified date appendedchangeAllFilenameSuffix
(File file, String oldSuffix, String newSuffix, boolean delete) Changes all filenames with the specified suffixdefault boolean
changeFilenameSuffix
(File file, String newSuffix) Changes the suffix of a filename.default boolean
changeFilenameSuffix
(File file, String newSuffix, boolean delete) Changes the suffix of the given filedefault boolean
forceToMoveFile
(File srcFile, File destinationFile) Moves the specified source file to the given destination filedefault boolean
Moves the specified source file to the given destination directorydefault boolean
renameFile
(File fileToRename, File newFileName) This method renames a given file.default boolean
renameFile
(File fileToRename, File newFileName, boolean delete) Renames the file, with an option to delete the originaldefault boolean
renameFile
(File fileToRename, String newFileNameWithoutAbsolutePath) Renames the given file, allowing specification of a new file name without an absolute pathdefault File
renameFileWithSystemtime
(File fileToRename) Renames a file with the system time appended
-
Method Details
-
appendSystemTimeToFilename
Returns the filename from the given file with the system time appended- Parameters:
fileToRename
- the file to rename- Returns:
- the filename with the system time appended
-
appendSystemTimeToFilename
Returns the filename from the given file with the specified date appended- Parameters:
fileToRename
- the fileadd2Name
- the date to add- Returns:
- the filename with the specified date appended
-
changeAllFilenameSuffix
default List<File> changeAllFilenameSuffix(File file, String oldSuffix, String newSuffix, boolean delete) throws IOException, FileDoesNotExistException, FileIsADirectoryException Changes all filenames with the specified suffix- Parameters:
file
- the directory in which to change filenamesoldSuffix
- the suffix to replacenewSuffix
- the new suffixdelete
- if true, deletes files with the same name after renaming- Returns:
- a list of files that could not be deleted if delete is true
- Throws:
IOException
- if an I/O exception occursFileDoesNotExistException
- if the file does not existFileIsADirectoryException
- if the file is a directory
-
changeFilenameSuffix
default boolean changeFilenameSuffix(File file, String newSuffix, boolean delete) throws IOException, FileDoesNotExistException, FileIsADirectoryException Changes the suffix of the given file- Parameters:
file
- the file to changenewSuffix
- the new suffixdelete
- if true, deletes the original file after renaming- Returns:
- true if the file was renamed successfully
- Throws:
IOException
- if an I/O exception occursFileDoesNotExistException
- if the file does not existFileIsADirectoryException
- if the file is a directory
-
renameFile
default boolean renameFile(File fileToRename, File newFileName, boolean delete) throws IOException, FileIsADirectoryException Renames the file, with an option to delete the original- Parameters:
fileToRename
- the file to renamenewFileName
- the new filenamedelete
- if true, deletes the original file after renaming- Returns:
- true if the file was renamed successfully
- Throws:
IOException
- if an I/O exception occursFileIsADirectoryException
- if the file is a directory
-
renameFileWithSystemtime
default File renameFileWithSystemtime(File fileToRename) throws IOException, FileIsADirectoryException Renames a file with the system time appended- Parameters:
fileToRename
- the file to rename- Returns:
- the renamed file with the system time
- Throws:
IOException
- if an I/O exception occursFileIsADirectoryException
- if the file is a directory
-
changeFilenameSuffix
default boolean changeFilenameSuffix(File file, String newSuffix) throws IOException, FileDoesNotExistException, FileIsADirectoryException Changes the suffix of a filename. Example: test.dat to test.xxx- Parameters:
file
- the file to changenewSuffix
- the new suffix, starting with a dot, e.g., ".xxx"- Returns:
- true if the file was renamed successfully
- Throws:
IOException
- if an I/O exception occursFileDoesNotExistException
- if the file does not existFileIsADirectoryException
- if the file is a directory
-
forceToMoveFile
default boolean forceToMoveFile(File srcFile, File destinationFile) throws IOException, FileIsADirectoryException Moves the specified source file to the given destination file- Parameters:
srcFile
- the source filedestinationFile
- the destination file- Returns:
- true if the file was moved successfully
- Throws:
IOException
- if an I/O exception occursFileIsADirectoryException
- if the source or destination is a directory
-
moveFile
Moves the specified source file to the given destination directory- Parameters:
srcFile
- the source filedestDir
- the destination directory- Returns:
- true if the file was moved successfully
- Throws:
IOException
- if an I/O exception occursFileIsADirectoryException
- if the source or destination is a directory
-
renameFile
default boolean renameFile(File fileToRename, String newFileNameWithoutAbsolutePath) throws IOException, FileIsADirectoryException, FileDoesNotExistException Renames the given file, allowing specification of a new file name without an absolute path- Parameters:
fileToRename
- the file to renamenewFileNameWithoutAbsolutePath
- the new name for the file without absolute path- Returns:
- true if the file was renamed successfully
- Throws:
IOException
- if an I/O exception occursFileIsADirectoryException
- if the file is a directoryFileDoesNotExistException
- if the file does not exist
-
renameFile
default boolean renameFile(File fileToRename, File newFileName) throws IOException, FileIsADirectoryException This method renames a given file. For instance if we have a file which we want to rename with the path "/tmp/test.dat" to "/tmp/renamed.dat" then you call the method as follow: renameFile(new File("C://tmp//test.dat"), new File("C://tmp//renamed.dat"));- Parameters:
fileToRename
- The file to rename.newFileName
- The new name from the file.- Returns:
- 's true if the file was renamed otherwise false.
- Throws:
IOException
- Signals that an I/O exception has occurred.FileIsADirectoryException
- the file is A directory exception
-