Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Monday, 8 January 2018

Java program to connect with URL and read content

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
public class MyUrlContentRead {
public static void main(String[] args)
{
URL url = null;
InputStream is = null;
try {
url = new URL("http://www.m4513.blogspot.com");
is = url.openStream();
byte[] b = new byte[8];
while(is.read(b) != -1){
System.out.print(new String(b));
}
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}

No comments:

Post a Comment