:::::::怎样根据给定的url,将相应的html文件下载到本地??? urlconnection读取HTTP包文的BODY部分,再存储 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*;import java.net.*;public class URLClient {protected URLConnection connection;public static void main(String[] args) { URLClient client = new URLClient(); String yahoo = client.getDocumentAt("http://www.yahoo.com"); System.out.println(yahoo); }public String getDocumentAt(String urlString) { StringBuffer document = new StringBuffer(); try { URL url = new URL(urlString); URLConnection conn = url.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line = null; while ((line = reader.readLine()) != null) document.append(line + "\n"); reader.close(); } catch (MalformedURLException e) { System.out.println("Unable to connect to URL: " + urlString); } catch (IOException e) { System.out.println("IOException when connecting to URL: " + urlString); } return document.toString(); }} http://expert.csdn.net/Expert/topic/2927/2927495.xml?temp=.9325525那里有你要的答案,只要前面加个http就行了!!! 这个关机命令怎么用不了 JPA 主子表 如何一起保存? 研究 初学+菜鸟提问:(有关类的) 几个疑问 我写了个判断是不是中文的小程序!想请教有没有更好的方法!~~~~~~~~~~~~~~~ 如何修改NetworkInterface的地址 怎样让Button显示Icon? 问一个超级菜的问题:java中怎样弹出一个信息框,就像VB的messagebox一样? JFrame有没有可能通过点击事件使窗口变化,该怎么写啊。 一个在Tomcat下运行Servlet的问题 -- 困扰了N天了,高手请帮忙啊!! 初来乍到,遵守诺言,Kosling请进来领分!
import java.net.*;
public class URLClient {
protected URLConnection connection;
public static void main(String[] args) {
URLClient client = new URLClient();
String yahoo = client.getDocumentAt("http://www.yahoo.com");
System.out.println(yahoo);
}public String getDocumentAt(String urlString) {
StringBuffer document = new StringBuffer();
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null)
document.append(line + "\n");
reader.close();
} catch (MalformedURLException e) {
System.out.println("Unable to connect to URL: " + urlString);
} catch (IOException e) {
System.out.println("IOException when connecting to URL: " + urlString);
}
return document.toString(); }
}
那里有你要的答案,只要前面加个http就行了!!!