Java : AtomicMoveNotSupportedException with Examples

AtomicMoveNotSupportedException (Java SE 23 & JDK 23) in Java with Examples.
You will find code samples for most of the AtomicMoveNotSupportedException methods.


Summary

Checked exception thrown when a file cannot be moved as an atomic file system operation.

Class diagram

System.out.println(System.getProperty("os.name")); // Windows 11

final var source = Path.of("D:", "java-work", "src.txt");
System.out.println(source); // D:\java-work\src.txt

final var target = Path.of("R:", "java-work", "dst.txt");
System.out.println(target); // R:\java-work\dst.txt

Files.createFile(source);

System.out.println(Files.exists(source)); // true
System.out.println(Files.exists(target)); // false

try {
    Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException e) {
    System.out.println("AtomicMoveNotSupportedException!");
}

// Result
// ↓
//AtomicMoveNotSupportedException!

Constructors

AtomicMoveNotSupportedException (String source, String target, String reason)

Constructs an instance of this class.

final var e = new AtomicMoveNotSupportedException("aaa.txt", "bbb.txt", "Reason!");
System.out.println(e); // java.nio.file.AtomicMoveNotSupportedException: aaa.txt -> bbb.txt: Reason!
System.out.println(e.getFile()); // aaa.txt
System.out.println(e.getOtherFile()); // bbb.txt
System.out.println(e.getReason()); // Reason!

Methods declared in FileSystemException

getFile, getMessage, getOtherFile, getReason

Please see the link below.

Methods declared in Throwable

addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString

Please see the link below.


Related posts

To top of page