In java.net.url
there is a getFile()
method and a getPath()
method.
In my testing, they both return the same result: the full path and file after the domain name trailing slash.
For instance, http://www.google.com/x/y/z.html
returns x/y/z.html
for both methods.
Could someone elaborate on the Javadocs?
URL getFile() method in Java with Examples The getFile() function is a part of URL class. The function getFile() returns the file name of a specified URL. The getFile() function returns the path and the query of the URL.
The getPath() method is a part of File class. This function returns the path of the given file object. The function returns a string object which contains the path of the given file object.
Simply put, getPath() returns the String representation of the file's abstract pathname. This is essentially the pathname passed to the File constructor. So, if the File object was created using a relative path, the returned value from getPath() method would also be a relative path.
URL.getFile():
Gets the file name of this URL. The returned file portion will be the same as getPath(), plus the concatenation of the value of getQuery(), if any. If there is no query portion, this method and getPath() will return identical results.
The URL.getFile()
javadocs say this:
Gets the file name of this URL. The returned file portion will be the same as getPath(), plus the concatenation of the value of getQuery(), if any. If there is no query portion, this method and getPath() will return identical results.
They will be the same unless there is a query string, e.g. a ?somename=value&somethingelse=value2
in the URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With