I want to extract the name of immediate directory with the filename. For example c:/wallpapers/images/images.gif I just want to retrieve images/images.gif.开发者_如何转开发 How can I do this?
String shortenedPath(String path) {
File complete = new File(path);
String parentDir = complete.getParent().getName();
File shortened = new File(parentDir, complete.getName());
return shortened.toString();
}
精彩评论