Java Utililty Methods Path File Move mio

List of utility methods to do Path File Move mio

Description

The list of methods to do Path File Move mio are organized into topic(s).

Method

Pathmove(Path from, Path to)
Move source file into target file if the target file exists, then the target file is replaced.
return Files.move(from, to, StandardCopyOption.REPLACE_EXISTING);
voidmove(Path source, Path destination)
Attempts to move the file represented by the specified Path to the specified destination atomically, resorting to moving it non-atomically if atomic operations are not supported by the source or destination file system.
try {
    Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException e) {
    Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING);
voidmoveDirectory(Path srcPath, Path destPath)
move Directory
if (!srcPath.toFile().isDirectory()) {
    throw new IOException(srcPath.toAbsolutePath().toString() + " is not a directory!");
if (!destPath.toFile().exists()) {
    destPath.toFile().mkdirs();
Files.move(srcPath, destPath, StandardCopyOption.REPLACE_EXISTING);
voidmoveFile(Path from, Path to)
move File
Files.move(from, to, StandardCopyOption.REPLACE_EXISTING);
voidmoveFile(Path source, Path target)
Moves the file from source to target.
try {
    Files.move(source, target);
} catch (Exception ex) {
    throw new RuntimeException(
            "Can not move the source file " + source.toString() + " to target " + target.toString(), ex);
voidmoveFile(Path source, Path target, boolean prompt)
move File
CopyOption[] options = new CopyOption[] { REPLACE_EXISTING };
if (!prompt || Files.notExists(target)) 
    try {
        Files.move(source, target, options);
    } catch (IOException x) {
        System.err.format("Unable to copy: %s: %s%n", source, x);
voidmoveFile(Path tempPath, Path defPath)
move File
try {
    Files.move(tempPath, defPath, StandardCopyOption.REPLACE_EXISTING); 
} catch (FileAlreadyExistsException faee) {
    throw new FileAlreadyExistsException(defPath.toString(), tempPath.toString(),
            "File already exists: " + defPath); 
} catch (IOException ex) { 
    throw new IOException("Can't move " + tempPath + " to " + defPath + ".", ex);
voidmoveFile(String pathBefore, String pathAfter)
move File
copyFile(pathBefore, pathAfter);
deleteFile(pathBefore);
voidmoveFile(String workspacePathOld, String workspacePathNew)
move File
createFoldersIfNecessary(workspacePathNew);
Path pathOld = FileSystems.getDefault().getPath(workspacePathOld);
Path pathNew = FileSystems.getDefault().getPath(workspacePathNew);
Files.move(pathOld, pathNew);