The java.net.URI relativize method is used to create a relative URI that represents the difference between two URIs. It returns a new URI that is relative to the URI used as an argument in the method. This method can be used to make relative URIs, which are useful in creating links and redirects.
Suppose we have two URIs:
URI 1: https://www.example.com/path/to/file.html URI 2: https://www.example.com/path/
The relativize method can be used to create a relative URI for the file.html URI as follows:
URI 1: https://www.example.com/path/to/file.html URI 2: https://www.example.com/path/ Relative URI: to/file.html
This represents the difference between the two URIs.
URI uri1 = new URI("https://www.example.com/path/to/file.html"); URI uri2 = new URI("https://www.example.com/path/"); URI relativeURI = uri2.relativize(uri1); System.out.println(relativeURI);
This code uses the relativize method to create a relative URI for the file.html URI.
This method is part of the java.net package.
Java URI.relativize - 26 examples found. These are the top rated real world Java examples of java.net.URI.relativize extracted from open source projects. You can rate examples to help us improve the quality of examples.