java - How to get FolderName and FileName from the DirectoryPath -


i have directorypath "data/data/in.com.jotsmart/app_custom/foldername/filename" stored string in arraylist

like

arraylist<string> a; a.add("data/data/in.com.jotsmart/app_custom/page01/note01.png"); 

now path want page01 seperate string , note01 seperate string , stored 2 string variable. tried lot, not able result. if 1 knows me solve out.

f.getparent()

returns pathname string of abstract pathname's parent, or null if pathname not name 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 valid representation of file in 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(".")); } } 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -