Java URLConnection .setDoOutput (boolean dooutput)

Syntax

URLConnection.setDoOutput(boolean dooutput) has the following syntax.

public void setDoOutput(boolean dooutput)

Example

In the following code shows how to use URLConnection.setDoOutput(boolean dooutput) method.


/* w  w w .  jav  a  2  s .c om*/
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;

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.setDoOutput(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