开发者

How to extract the name of immediate directory with the filename using lastIndexOf method?

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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜