Java URL getPath() Method

24 Mar 2025 | 1 min read

The getPath() method of URL class is used to get the path part of this URL. It returns an empty string if one does not exist.

Syntax

Returns

The path part of this URL, or an empty string if one does not exist

Since

1.3

Example 1

Output:

 Url: https://www.tpointtech.com/collections-in-java#collectionmethods Path of File in given url is : /collections-in-java 

Example 2

Output:

 Given URL is : https://localhost/notic/note.jsp Path of url is : /notic/note.jsp 
Next TopicJava URL Class