import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; import java.net.URL; import java.net.MalformedURLException; public class URLTest{ public static void main(String[] args){ //设置系统网络代理服务器 //System.setProperty("http.proxyHost","192.168.1.1"); //System.setProperty("http.proxyHost","80"); try{ //实例化一个URL URL tirc = new URL("http://www.google.cn/"); //得到远程主机网页的字符流信息并封装给BufferedReader BufferedReader br = new BufferedReader(new InputStreamReader(tirc.openStream())); //将信息输出到屏幕上 while(br.readLine()!= null){ String s = br.readLine(); System.out.println(s); } br.close(); } catch(MalformedURLException e){ System.out.println(e); } catch(IOException e){ System.out.println(e); } } }