Java : AtomicMoveNotSupportedException 示例
Java 中的 AtomicMoveNotSupportedException (Java SE 23 & JDK 23) 及其示例。
您将找到大多数 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!");
}
// Result
// ↓
//AtomicMoveNotSupportedException!
Constructors
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!
Methods declared in FileSystemException
Methods declared in Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
请参阅下面的链接。