是否可以在java中获取图像的名称。图像来源是网址。
例如。 “http://172.16.2.42/apache_pb.png”
我需要输出“apache_pb.png”
答案 0 :(得分:2)
String s = "http://172.16.2.42/apache_pb.png";
int index = s.lastIndexOf('/');
String name = s.substring(index+1);
System.out.println(name);
答案 1 :(得分:2)
您可以使用URL
类中的辅助方法:
String file = new URL("http://172.16.2.42/apache_pb.png").getPath();
答案 2 :(得分:1)
URL#getFile()会为你做这件事吗?