Mega Code Archive

 
Categories / Java Tutorial / Network
 

Java net URLConnection

A URLConnection object represents a connection to a remote machine. You use it to read a resource from and write to a remote machine. To obtain an instance of URLConnection, call the openConnection method on a URL object. To use a URLConnection object to write: set the value of doOutput to true using setDoOutput methods: URL url = new URL ("http://www.google.com/"); InputStream inputStream = url.openStream (); has the same effect as URL url = new URL ("http://www.google.com/"); URLConnection urlConnection = url.openConnection (); InputStream inputStream = urlConnection.getInputStream ();