Languages

Java - how to get file name from absolute path string?

0 points
Asked by:
Indira
499

Can you tell me how to get the file name from the absolute path string in Java?

I created a file as follows:

Now when I use System.out.println(myDirectory); I get the absolute path of a file.

How do I only get the myFile.txt as a String?

1 answer
0 points
Answered by:
Nicola-Melendez
375

I found the solution.

Instead of:

use getName() method:

0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join