2017-07-17 52 views

回答

1

在你的具體情況是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 
相關問題