![](/img/trans.png)
[英]Cannot delete some files using SimpleFileVisitor in java.nio.file
[英]Creating files using java.nio.file Functionality
我正在閱讀oracle,以了解如何使用java.nio.file功能而不是java.io.File功能中的Path創建文件,這是示例代碼:
Path file = ...;
try {
// Create the empty file with default permissions, etc.
Files.createFile(file);
} catch (FileAlreadyExistsException x) {
System.err.format("file named %s" +
" already exists%n", file);
} catch (IOException x) {
// Some other sort of failure, such as permissions.
System.err.format("createFile error: %s%n", x);
}
但是...中有什么? 空間? 我應該在那里輸入什么?
用於保存文件
eg
Path path = Paths.get("src/main/resources/question.txt");
路徑對象是系統上文件或目錄的路徑的層次結構表示。 java.nio.file.Path接口是使用NIO 2 API的主要入口點。
創建路徑對象的最簡單方法是使用java.nio.files.Paths工廠類。 該類具有靜態的get()方法,該方法可用於獲取對文件或目錄的引用。 該方法接受一個字符串或一個字符串序列(它將連接起來以形成路徑)作為參數。 像File一樣,java.nio.file.Path可以引用文件系統中的絕對路徑或相對路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.