Posted in Java 12 years ago 1 min read
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class readUrl {
public static void main(String[] args) throws MalformedURLException, IOException {
URL url = new URL("http://google.com");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String inputLine;
while ((inputLine = br.readLine()) != null) {
System.out.println(inputLine);
}
br.close();
}
}
Output program:
<!doctype html><html itemscope="itemscope" itemtype="http://schema.org/WebPage"><head><meta content= .....dst..... google.timers.load.t.prt=e=(new Date).getTime();})();</script></body></html>Jika output tersebut disimpan ke dalam file html, maka dapat menampilkan bentuk dari website seperti gambar berikut ini: [caption id="" align="aligncenter" width="498"]
Java ReadURL[/caption]
Referensi: Oracle Documentation
Semoga bermanfaat.