Java Path File Move mio move(Path source, Path destination)

Here you can find the source of move(Path source, Path destination)

Description

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.

License

Open Source License

Parameter

Parameter Description
source The source path.
destination The destination path.

Exception

Parameter Description
IOException If the file could not be moved.

Declaration

public static void move(Path source, Path destination) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.Files;
import java.nio.file.Path;

import java.nio.file.StandardCopyOption;

public class Main {
    /**/* ww w  .  j  av  a2s. c om*/
     * Attempts to move the file represented by the specified {@link 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.
     *
     * @param source The source path.
     * @param destination The destination path.
     * @throws IOException If the file could not be moved.
     */
    public static void move(Path source, Path destination) throws IOException {
        try {
            Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
        } catch (AtomicMoveNotSupportedException e) {
            Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING);
        }
    }
}

Related

  1. move(Path from, Path to)
  2. moveDirectory(Path srcPath, Path destPath)
  3. moveFile(Path from, Path to)
  4. moveFile(Path source, Path target)
  5. moveFile(Path source, Path target, boolean prompt)