Java API Tutorial - Java URLConnection .setReadTimeout (int timeout)








Syntax

URLConnection.setReadTimeout(int timeout) has the following syntax.

public void setReadTimeout(int timeout)

Example

In the following code shows how to use URLConnection.setReadTimeout(int timeout) method.

//from  w w w  .  j a  v a  2  s  . c  o m
import java.net.URL;
import java.net.URLConnection;

public class Main {

  public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();
    
    uc.setReadTimeout(1000);
    System.out.println(uc.getReadTimeout());
  }

}

The code above generates the following result.