Get file name from URL

前端 未结 27 1640
[愿得一人]
[愿得一人] 2020-11-28 02:24

In Java, given a java.net.URL or a String in the form of http://www.example.com/some/path/to/a/file.xml , what is the easiest way to g

27条回答
  •  没有蜡笔的小新
    2020-11-28 03:21

    I've come up with this:

    String url = "http://www.example.com/some/path/to/a/file.xml";
    String file = url.substring(url.lastIndexOf('/')+1, url.lastIndexOf('.'));
    

提交回复
热议问题