View RSS Feed

Java Socket

Java Networking: URL + URLConnection

Rate this Entry
by , 04-25-2012 at 11:31 PM (956 Views)
Two classes are present in java.net package. URLConnection class & URL class.Client connections are created by these classes to the web servers. Here is a code given as an example:
Java Code:
URL url = new URL("http://test.com");

URLConnection urlConnection = url.openConnection();
InputStream input = urlConnection.getInputStream();

int data = input.read();
while(data != -1){
    System.out.print((char) data);
    data = input.read();
}
input.close();

Submit "Java Networking: URL + URLConnection" to Facebook Submit "Java Networking: URL + URLConnection" to Digg Submit "Java Networking: URL + URLConnection" to del.icio.us Submit "Java Networking: URL + URLConnection" to StumbleUpon Submit "Java Networking: URL + URLConnection" to Google

Categories
Tutorial

Comments