如何获取URL的路径 [英] How to get the path of a URL
本文介绍了如何获取URL的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个URL,如何检索其路径部分?
Have a URL, how to retrieve its path part?
http://www.costo.com/test1/test2
如何获得test1 / test2
How to get "test1/test2"
推荐答案
你想要这样的东西:
String path = new URL("http://www.costo.com/test1/test2").getPath();
实际上,它会给你 / test1 / test2
。您只需删除第一个 /
即可获得所需内容:
Actually that'll give you /test1/test2
. You'll just have to remove the first /
to get what you want:
path = path.replaceFirst("/", "");
现在你将拥有 test1 / test2
在路径
。
这篇关于如何获取URL的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文