Java : AtomicMoveNotSupportedException - API使用例
AtomicMoveNotSupportedException (Java SE 23 & JDK 23) の使い方まとめです。
ほとんどのメソッドにサンプルコードがあります。
APIドキュメントのおともにどうぞ。
概要
原子的なファイル・システム操作としてファイルを移動できない場合にスローされるチェック例外です。
AtomicMoveNotSupportedException はチェック例外です。
アトミックな移動操作ができなかったときに発生します。
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!");
}
// 結果
// ↓
//AtomicMoveNotSupportedException!
コンストラクタ
AtomicMoveNotSupportedException (String source, String target, String reason)
このクラスのインスタンスを構築します。
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!
FileSystemExceptionで宣言されたメソッド
getFile, getMessage, getOtherFile, getReason
「Java API 使用例 : FileSystemException」をご参照ください。
Throwableで宣言されたメソッド
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
「Java API 使用例 : Throwable」をご参照ください。