Java URLConnection .setDoInput (boolean doinput)

Syntax

URLConnection.setDoInput(boolean doinput) has the following syntax.

public void setDoInput(boolean doinput)

Example

In the following code shows how to use URLConnection.setDoInput(boolean doinput) method.


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
/*w  w w  . j  av  a 2 s . c o m*/
public class Main {
  public static void main(String args[]) throws Exception {
    String fullURL = args[0];
    URL u = new URL(fullURL);
    URLConnection conn = u.openConnection();
    conn.setDoInput(true);
    OutputStream theControl = conn.getOutputStream();
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl));
    for (int i = 1; i < args.length; i++) {
      out.write(args[i] + "\n");
    }
    out.close();
    InputStream theData = conn.getInputStream();

    String contentType = conn.getContentType();
    if (contentType.toLowerCase().startsWith("text")) {
      BufferedReader in = new BufferedReader(new InputStreamReader(theData));
      String line;
      while ((line = in.readLine()) != null) {
        System.out.println(line);
      }
    }
  }
}

   




















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder