News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

URLConnection getContent Example

Started by VelMurugan, Dec 20, 2008, 11:20 PM

Previous topic - Next topic

VelMurugan

URLConnection getContent Example

URLConnection class getContent example. This example shows you how to use getContent method.

URLConnection class getContent example. public Object getContent(Class[] classes) throws IOException Retrieves the contents of this URL connection.

Here is the code

/*
* @ # GetContent1.java
* A class repersenting use to getContent
* method of URLConnection class in java.net package
* version 23 June 2008
* author Rose India
*/

import java.io.*;
import java.net.*;

public class GetContent1 {

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

        URL url = new URL("http://localhost:8080/net/listnets.jsp");
        URLConnection connection = url.openConnection();

        Class type[] = {String.class, Reader.class, URLConnection.class};
        Object obj = connection.getContent(type);

        if (obj == null) {
         throw new Exception("None of requested type were abailable");
        }
    }
}


Output

QuoteException in thread "main" java.lang.Exception: None of requested type were abailable
        at GetContent1.main(GetContent1.java:23)

Source : codingdiary