URI.getPort() has the following syntax.
public int getPort()
In the following code shows how to use URI.getPort() method.
import java.net.URI; import java.net.URISyntaxException; /* w w w. jav a 2 s. c o m*/ public class Main { public static void main(String[] args) throws NullPointerException, URISyntaxException { URI uri = new URI("http://www.java2s.com:8080/yourpath/fileName.htm"); System.out.println("URI : " + uri); System.out.println(uri.getPort()); } }
The code above generates the following result.