Java URL sameFile Method

The sameFile() method of URL class compares two URLs, excluding the fragment component. It returns true if this URL and the other argument are equal without considering the fragment component.

Syntax

Parameter

other - the URL to compare against.

Returns

true if they reference the same remote object; false otherwise.

Example 1

Output:

Url1 : https://www.javatpoint.com/aptitude/quantitative
Url2 : https://www.javatpoint.com/
 ***** compareing both url ***** 
 Both url has different file 

Example 2

Output:

Enter any url 
https://www.javatpoint.com/
File of Both url are equal : true

Example 3

Output:

Both BaseUrl and relativeURL are equal? : false
Next TopicJava URL Class




Latest Courses