Java URL getFile() Method

The getFile() method of URL class returns the file name of the URL. The returned file portion will be the same as getPath(), plus the concatenation of the value of getQuery() if any.

Syntax

Parameter

NA

Returns

the file name of this URL, or an empty string if one does not exist

Example 1

Output:

Url: https://www.javatpoint.com/java-threadpoolexecutor
File name in given url is : /java-threadpoolexecutor

Example 2

Output:

Enter any url 
https://www.javatpoint.com/java-threadpoolexecutor
File name in given url is : /java-threadpoolexecutor

Example 3

Output:

Url1: https://www.javatpoint.com/URL-class
 Url2: https://www.javatpoint.com/URL-class
File name in given url1 is : /URL-class
File name in given url2 is : /URLConnection-class
Next TopicJava URL Class




Latest Courses