yumen
真郁闷,刚才输了一大堆内容,居然说回复内容不能为空
不多说了,源码如下,自己看吧。
String sCurrentLine = "";
String sTotalString = "";
InputStream l_urlStream;
URL l_url = new URL("http://*****/**.**");
HttpURLConnection l_connection = (HttpURLConnection) l_url.openConnection();
l_connection.connect();
l_urlStream = l_connection.getInputStream();
BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
while ((sCurrentLine = l_reader.readLine()) != null)
{
sTotalString += sCurrentLine;
}
2008-05-17 12:00:06 被【wbchn】修改
自己试试就知道了
import java.io.*;
import java.net.*;
import java.util.*;
/*
* 创建日期 2008-4-21
* @author yaos
*
*/
public class scan
{
public static String getHTML(String url)
{
String str, ResStr;
ResStr = new String();
try
{
URL currenturl = new URL(url);
URLConnection con = currenturl.openConnection();
HttpURLConnection httpcon = (HttpURLConnection) con;
if(httpcon.getResponseCode() == HttpURLConnection.HTTP_OK)
{
if(httpcon.getContentType().startsWith("text/html"))
{
InputStreamReader in = new InputStreamReader(con.getInputStream());
BufferedReader buf=new BufferedReader(in);
while ((str = buf.readLine()) != null)
{
ResStr += (str+"\r\n");
}
buf.close();
in.close();
}
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return ResStr;
}
public static void main(String [] args)
{
String res = getHTML("http://www.hit.edu.cn/");
System.out.println(res);
}
}
