Request web page in Java example
long t0 = System.currentTimeMillis();
DataInputStream dis;
try {
String urlString = "http://www.ibm.com";
URL url = new URL(urlString);
dis = new DataInputStream(url.openConnection().getInputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(dis));
String total = "";
String line = "";
While ((line = in.readLine()) != null) {
total += line;
}
in.close();
} catch (Exception e) {
System.out.println(e);
}
long t1 = System.currentTimeMillis();
System.out.println("time used = " + (t1-t0) + " ms.");
You can Writing to a URLConnection too.
0 Comments:
Post a Comment
<< Home