1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| import java.net.*;
import java.io.*;
import java.util.Properties;
public class URLUtils {
public static void main(String s[]) {
URLUtils.dump("http://www.yahoo.com");
System.out.println("**************");
}
public static void dump(String URLName){
try {
DataInputStream di = null;
FileOutputStream fo = null;
byte [] b = new byte[1];
// PROXY
URL u = new URL(URLName);
HttpURLConnection con = (HttpURLConnection) u.openConnection();
//
// it's not the greatest idea to use a sun.misc.* class
// Sun strongly advises not to use them since they can
// change or go away in a future release so beware.
//
di = new DataInputStream(con.getInputStream());
while(-1 != di.read(b,0,1)) {
System.out.print(new String(b));
}
}
catch (Exception e) {
e.printStackTrace();
}
}
} |
Partager