0
有人回答one of my questions使用path.getFileName().toFile()
而不是path.toFile()
。是有原因的,還是應該只使用path.toFile()
?是否有理由在將文件轉換爲文件之前獲取路徑的文件名?
有人回答one of my questions使用path.getFileName().toFile()
而不是path.toFile()
。是有原因的,還是應該只使用path.toFile()
?是否有理由在將文件轉換爲文件之前獲取路徑的文件名?
在你的具體情況是path.getFileName().toFile().getName()
在這種情況下path.toFile().getName()
會給你同樣的結果。
但是一般來說path.getFileName().toFile()
和path.toFile()
會返回不同的文件。
這裏有個小例子。
Path path = FileSystems.getDefault().getPath("foo", "bar", "buzz");
System.out.println(path.getFileName().toFile());
System.out.println(path.toFile());
這給我們
buzz
foo\bar\buzz
爲什麼不向誰回答你問題的人? – CraigR8806
對不起。我會像你下次說的那樣做。 – viniciussss