The difference between the GetFile () and the GetPath () method of the URL (goto)

Source: Internet
Author: User
Tags goto

Go from blog: http://blog.csdn.net/l375852247/article/details/7999063

Importjava.net.MalformedURLException; ImportJava.net.URL;  Public classDD {/**      * @paramargs*/       Public Static voidMain (string[] args) {Try{URL URL=NewURL ("file://ftp.yoyodyne.com/pub/files/foobar.txt?id=123456"); System.out.println ("Url.getfile () =" +url.getfile ()); System.out.println ("Url.getpath () =" +Url.getpath ()); } Catch(malformedurlexception e) {e.printstacktrace (); }      }  }  

Results returned:

Url.getfile () =/pub/files/foobar.txt?id=123456
Url.getpath () =/pub/files/foobar.txt

When the above

Change into

File://ftp.yoyodyne.com/pub/files/foobar.txt  

When

Results returned:

Url.getfile () =/pub/files/foobar.txt
Url.getpath () =/pub/files/foobar.txt

The Java docs document says:

The URL.getFile() Javadocs say this:

Gets the file name of this URL. The returned file portion would be the same as GetPath (), plus the concatenation of the value of Getquery (), if any. If There is no query portion, the This method and GetPath () would return identical results.

They'll be the same unless there are a query string, e.g. a in the ?somename=value&somethingelse=value2 URL.

I was a novice before I had not known what was going on, now understand!

The difference between the GetFile () and the GetPath () method of the URL (goto)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.