CodesJava

Easy learning with example program codes

Read or get contents of a url in java


Get contents of a url in java

package com.codesjava;
 
import java.io.InputStream;
import java.net.URL;
 
public class URLTest {
  public static void main(String args[]){
	try {
	    URL url = new URL("https://codesjava.com");
	    InputStream inputStream  = url.openStream();
            byte[] b = new byte[8];
            while(inputStream.read(b) != -1){
                System.out.print(new String(b));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
  }
}
Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki