Java URL getFile() Method

24 Mar 2025 | 2 min read

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.tpointtech.com/java-threadpoolexecutor File name in given url is : /java-threadpoolexecutor 

Example 2

Output:

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

Example 3

Output:

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