Java : FileSystemException 示例
Java 中的 FileSystemException (Java SE 22 & JDK 22) 及其示例。
您将找到大多数 FileSystemException 方法的代码示例。
注解 :
- 本文可能使用了翻译软件以方便阅读。 另请查看英文原文。
简介
final var file = Path.of("R:", "java-work", "aaa.txt");
System.out.println(file); // R:\java-work\aaa.txt
System.out.println(Files.notExists(file)); // true
try {
Files.delete(file);
} catch (FileSystemException e) {
System.out.println(e);
}
// Result
// ↓
//java.nio.file.NoSuchFileException: R:\java-work\aaa.txt
final var file = Path.of("R:", "java-work", "aaa.txt");
System.out.println(file); // R:\java-work\aaa.txt
Files.createFile(file);
System.out.println(Files.exists(file)); // true
try {
Files.createFile(file);
} catch (FileSystemException e) {
System.out.println(e);
}
// Result
// ↓
//java.nio.file.FileAlreadyExistsException: R:\java-work\aaa.txt
Constructors
FileSystemException (String file)
final var e = new FileSystemException("aaa.txt");
System.out.println(e); // java.nio.file.FileSystemException: aaa.txt
System.out.println(e.getFile()); // aaa.txt
FileSystemException (String file, String other, String reason)
final var e = new FileSystemException("aaa.txt", "bbb.txt", "Reason!");
System.out.println(e); // java.nio.file.FileSystemException: 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
String getFile ()
final var e = new FileSystemException("aaa.txt");
System.out.println(e); // java.nio.file.FileSystemException: aaa.txt
System.out.println(e.getFile()); // aaa.txt
String getMessage ()
final var e = new FileSystemException("aaa.txt", "bbb.txt", "Reason!");
System.out.println(e); // java.nio.file.FileSystemException: aaa.txt -> bbb.txt: Reason!
System.out.println(e.getMessage()); // aaa.txt -> bbb.txt: Reason!
String getOtherFile ()
final var e = new FileSystemException("aaa.txt", "bbb.txt", "Reason!");
System.out.println(e); // java.nio.file.FileSystemException: aaa.txt -> bbb.txt: Reason!
System.out.println(e.getOtherFile()); // bbb.txt
String getReason ()
final var e = new FileSystemException("aaa.txt", "bbb.txt", "Reason!");
System.out.println(e); // java.nio.file.FileSystemException: aaa.txt -> bbb.txt: Reason!
System.out.println(e.getReason()); // Reason!
Methods declared in Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
请参阅下面的链接。