URI uri = new URI("https://www.example.com/path/to/resource"); String path = uri.getPath(); System.out.println(path);
/path/to/resource
URI uri = new URI("ftp://ftp.example.com/files/file.txt"); String path = uri.getPath(); System.out.println(path);
/files/file.txtThis example creates a URI object for the URL "ftp://ftp.example.com/files/file.txt", and then calls the getPath() method to get the path "/files/file.txt". It then prints the path to the console. The java.net.URI class is part of the Java Standard Library, which is included with all Java installations. Therefore, it does not require any external package or library.