Here I am going to show example which works with URL.
Each URL(Uniform Resource Locator) unambiguously identifies the location of a resource on the Internet.
Example shows how to connect to an URL,download its data and show it in console via System.out
import java.io.IOException;import java.io.InputStream;import java.net.MalformedURLException;import java.net.URL;public class Main{ public static void main(String[] args) throws IOException{ InputStream inputStream = null; try{ URL u = new URL("http://thedevelopersinfo.com"); inputStream = u.openStream(); for (int c = inputStream.read();c != -1;c = inputStream.read()){System.out.write(c); } } catch (MalformedURLException ex){ ex.printStackTrace(); } finally{ if (inputStream != null){inputStream.close(); } } }}Download code from this post.
No related posts.

Recent Comments