开发者

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

开发者 https://www.devze.com 2023-03-05 21:26 出处:网络
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 s

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

精彩评论

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