In java, what's the best way to read a url and split it into its parts?

前端 未结 4 986
攒了一身酷
攒了一身酷 2021-01-18 01:27

Firstly, I am aware that there are other posts similar, but since mine is using a URL and I am not always sure what my delimiter will be, I feel that I am alright posting my

4条回答
  •  囚心锁ツ
    2021-01-18 02:04

    The URL class pretty much does this, look at the tutorial. For example, given this URL:

    http://example.com:80/docs/books/tutorial/index.html?name=networking#DOWNLOADING
    

    This is the kind of information you can expect to obtain:

    protocol = http
    authority = example.com:80
    host = example.com
    port = 80
    path = /docs/books/tutorial/index.html
    query = name=networking
    filename = /docs/books/tutorial/index.html?name=networking
    ref = DOWNLOADING
    

提交回复
热议问题