Someone answered one of my questions using path.getFileName().toFile()
instead of just path.toFile()
. Is there a reason for that or should I use just path.toFile()
?
Asked
Active
Viewed 40 times
0

viniciussss
- 4,404
- 2
- 25
- 42
-
Why not ask the person who answered your question? – CraigR8806 Jul 17 '17 at 14:01
-
Sorry. I'll do like you said next time. – viniciussss Jul 17 '17 at 14:15
1 Answers
1
In your specific situation it was path.getFileName().toFile().getName()
in this case path.toFile().getName()
will give you same result.
But generally speaking path.getFileName().toFile()
and path.toFile()
will return different files.
Here small example.
Path path = FileSystems.getDefault().getPath("foo", "bar", "buzz");
System.out.println(path.getFileName().toFile());
System.out.println(path.toFile());
Which give us
buzz
foo\bar\buzz

talex
- 17,973
- 3
- 29
- 66