EN
Java - how to get file name from absolute path string?
1
answers
0
points
Can you tell me how to get the file name from the absolute path string in Java?
I created a file as follows:
String myDirectoryPath = "C:\\projects\\example\\myFile.txt";
File myDirectory = new File(myDirectoryPath);
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
I found the solution.
Instead of:
System.out.println(myDirectory);
use getName() method:
System.out.println(myDirectory.getName());
0 comments
Add comment