Class FileUtils
java.lang.Object
FileUtils
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation of this utility class. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyDirectory(Path sourceDir, Path destDir) Recursively copy a directory tree fromsourceDirtodestDir.static voidcopyDirectoryAtomically(Path sourceDir, Path destDir) Attempt to copy an entire directory atomically; if any copy fails the destination tree will be deleted to avoid partial state.static voidcopyDirectoryWithConflictHandling(Path sourceDir, Path destDir) Copy directory tree but prompt for conflicts.static voiddeleteDirectory(Path dir) Recursively delete a directory.static booleanhandleFileConflict(Path destPath) Prompt the user for conflict resolution when a destination path already exists.static booleanhasEnoughDiskSpace(Path sourceDir, Path destDir) Estimate whether the destination has enough usable space to copy the full contents of the source directory.static voidopenFolder(String path) Open the operating system's file browser at the given path.static booleanverifyIntegrity(Path sourceDir, Path destDir) Verify copied files match the source by checking file presence and size.
-
Constructor Details
-
FileUtils
private FileUtils()Private constructor to prevent instantiation of this utility class.
-
-
Method Details
-
copyDirectory
Recursively copy a directory tree fromsourceDirtodestDir. Existing files at the destination will be replaced.- Parameters:
sourceDir- root path to copy fromdestDir- root path to copy to- Throws:
IOException- when IO fails during traversal or copy
-
openFolder
Open the operating system's file browser at the given path.- Parameters:
path- filesystem path to open- Throws:
IOException- if the platform does not support Desktop operations or the path cannot be opened
-
hasEnoughDiskSpace
Estimate whether the destination has enough usable space to copy the full contents of the source directory. This is a best-effort check.- Parameters:
sourceDir- path to source directorydestDir- path to destination directory (used to query filesystem stats)- Returns:
- true when available space >= required size
- Throws:
IOException- on IO errors while computing sizes
-
copyDirectoryAtomically
Attempt to copy an entire directory atomically; if any copy fails the destination tree will be deleted to avoid partial state.- Parameters:
sourceDir- source directorydestDir- destination directory- Throws:
IOException- when copy or rollback fails
-
deleteDirectory
Recursively delete a directory. Errors during deletion are logged but do not stop the traversal.- Parameters:
dir- path to remove- Throws:
IOException- if an IO error prevents traversal
-
verifyIntegrity
Verify copied files match the source by checking file presence and size.- Parameters:
sourceDir- sourcedestDir- destination- Returns:
- true when every file exists in the destination and sizes match
- Throws:
IOException- on IO error
-
handleFileConflict
Prompt the user for conflict resolution when a destination path already exists.- Parameters:
destPath- conflicted destination path- Returns:
- true when user chooses to overwrite
-
copyDirectoryWithConflictHandling
public static void copyDirectoryWithConflictHandling(Path sourceDir, Path destDir) throws IOException Copy directory tree but prompt for conflicts. If the user declines for a specific file, that file is skipped while others continue.- Parameters:
sourceDir- source pathdestDir- destination path- Throws:
IOException- on IO failure
-