import java.net.*;
import java.io.*;
public class OpenUrl
{
public String getContent(String strUrl)
// 一个public方法,返回字符串,错误则返回"error open url"
{
try{
URL url=new URL(strUrl);
BufferedReader br=new BufferedReader(new InputStreamReader(url.openStream()));
String s="";
StringBuffer sb=new StringBuffer("");
while((s=br.readLine())!=null)
{
System.out.println(s);
sb.append(s+"/r/n");
}
br.close();
return sb.toString();
}catch(Exception e){
return "error open url" + strUrl;
}
}
public static void main(String args[])
{
//具体使用方法
OpenUrl ou=new OpenUrl();ou.getContent("http://www.sina.com/");
//System.out.println(ou.getContent("http://www.sina.com/"));
}
}