Monday, 4 December 2017

How to use URLConnection class in Java Programming

Learning Java Programming Made Easy

Java Connection Class:

The Java URLConnection class represents a communication link between the URL and the application. This class can be used to read and write data to the specified resource referred by the URL.

The openConnection() method of URL class returns the object of URLConnection class. Syntax:

public URLConnection openConnection()throws IOException{}

Example:


  1. import java.io.*;  
  2. import java.net.*;  
  3. public class URLConnectionExample {  
  4. public static void main(String[] args){  
  5. try{  
  6. URL url=new URL("http://www.javatpoint.com/java-tutorial");  
  7. URLConnection urlcon=url.openConnection();  
  8. InputStream stream=urlcon.getInputStream();  
  9. int i;  
  10. while((i=stream.read())!=-1){  
  11. System.out.print((char)i);  
  12. }  
  13. }catch(Exception e){System.out.println(e);}  
  14. }  
  15. }

1 comment:

  1. Տince the adrmin of this web site is ᴡorking, no uncertainty very ѕhortly it will bbe renowned, due to its feature contents.

    ReplyDelete

Welcome, happy learning

Charactor_At_Position

public class Char_At_Position { public static void main(String[] args) { String str = "Wankhede"; String rev=""...