Reputation: 8498
Is it possible to get the name of an image in java. The image source is a url.
For eg. "http://172.16.2.42/apache_pb.png"
I need the output "apache_pb.png"
Upvotes: 0
Views: 4353
Reputation: 19167
You can use this helper method from the URL
class:
String file = new URL("http://172.16.2.42/apache_pb.png").getPath();
Upvotes: 2
Reputation: 4397
String s = "http://172.16.2.42/apache_pb.png";
int index = s.lastIndexOf('/');
String name = s.substring(index+1);
System.out.println(name);
Upvotes: 2