How to get FolderName and FileName from the DirectoryPath
file, java
Solution
`f.getParent()`
Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.
For example
File f = new File("/home/jigar/Desktop/1.txt");
System.out.println(f.getParent());// /home/jigar/Desktop
System.out.println(f.getName()); //1.txt
Update: (based on update in question)
if `data/data/in.com.jotSmart/app_custom/page01/Note01.png` is valid representation of file in your file system then
for(String fileNameStr: filesList){
File file = new File(fileNameStr);
String dir = file.getParent().substring(file.getParent().lastIndexOf(File.separator) + 1);//page01
String fileName = f.getName();
if(fileName.indexOf(".")!=-1){
fileName = fileName.substring(0,fileName.lastIndexOf("."));
}
}
Problem
I have DirectoryPath: `data/data/in.com.jotSmart/app_custom/folderName/FileName` which is stored as a String in `ArrayList` Like ``` ArrayList<String> a; a.add("data/data/in.com.jotSmart/app_custom/page01/Note01.png"); ``` Now from this path I want to get `page01` as a separate string and `Note01` as a separate string and stored it into two string variables. I tried a lot, but I am not able to get the result. If anyone knows help me to solve this out.