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)