I do not think there is a magic method to get this straight. However, this should be good:
File f = new File("C:/aaa/bbb/ccc/ddd/test.java"); String path = f.getParent(); System.out.println(path.substring(path.lastIndexOf("\\")+1,path.length()));
f.getParent() may be null, so you should check it out.
EDIT: To make sure the result looks like this: C: / AAA / BBB / scc / ddd
Surasin Tancharoen Nov 19 '11 at 20:47 2011-11-19 20:47
source share