楼主的意图不表明,,
但至少一点可以肯定的. 你的while循环里面的条件永远成立. 所以死循环
你在那方面多入手看看吧`
但至少一点可以肯定的. 你的while循环里面的条件永远成立. 所以死循环
你在那方面多入手看看吧`
解决方案 »
- Java对数据库sql/hql操作实现同步
- 怎么让Jfreechart的时序图上的不同的曲线的数据点的值的颜色不一样?
- 急:如何查处cpu使用率高的sql语句?
- JSP通过ODBC连接MSSQL的问题
- exe4j生成的exe文件无法在其它电脑上运行,电脑都已安装java运行环境(jdk1.6,jre)
- 什么是Strust,spring,hibernate,简单描述下?
- 下列哪些可以用JNDI访问?
- ireport的问题!
- 求教:关于web service的几个问题,高手请指点,菜鸟一起学习
- 如何向SQLSERVER2000插入\修改\保存数据(向各位请教)
- hibernate
- JS问题,按年推算时间
URL url = new URL("http://www.baidu.com");
httpurlconnection = (HttpURLConnection) url.openConnection();
InputStream instream = httpurlconnection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(
instream));
String str;
while ((str = reader.readLine()) != null) {
System.out.println(str);
}
在jsp代码中获取到当前内容,也就打开这个页面也就获取到页面显示的内容
URL url = new URL("http://localhost/index.jsp");
InputStreamReader isr = new InputStreamReader(url.openStream());
BufferedReader br = new BufferedReader(isr);
FileOutputStream fileout = new FileOutputStream("d:\\index.txt");
String str;
while ((str = br.readLine()) != null) {
fileout.write(str.getBytes());
}
String code = "";
URLConnection uc = null;
URL url = null;
BufferedReader br = null;
try{
String tmp = "";
url = new URL(urlstr);
uc = url.openConnection();
uc.setConnectTimeout(1000 * 30);
uc.setReadTimeout(1000 * 30);
br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
while((tmp = br.readLine()) != null){
if(tmp.trim().length() > 0){
code += tmp + "\r\n";
}
}
}catch (IOException e) {
e.printStackTrace();
}finally{
try{
if(br != null){
br.close();
}
}catch(Exception exx){
}
}
return code;
}
你试试行不?
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.net.URL;public class Test{
public static void main(String[] args) throws Exception{
URL url = new URL("http://www.baidu.com");
InputStreamReader isr = new InputStreamReader(url.openStream());
BufferedReader br = new BufferedReader(isr);
FileOutputStream fileout = new FileOutputStream("d:\\a.txt");
String str;
while ((str = br.readLine()) != null) {
fileout.write(str.getBytes());
} }
}
代码经侧试没有问题。去找一下其他原因吧 结果如下
------------------------
<html><head><meta http-equiv=Content-Type content="text/html;charset=gb2312"><title>百度一下,你就知道 </title><style>body{margin:4px 0}p{margin:0;padding:0}img{border:0}td,p,#u{font-size:12px}#b,#u,#l td,a{font-family:arial}#kw{font:16px Verdana;height:1.78em;padding-top:2px}#b{height:30px;padding-top:4px}#b,#b a{color:#77c}#u{padding-right:10px;line-height:19px;text-align:right;margin:0 0 3px !important;margin:0 0 10px}#sb{height:2em;width:5.6em}#km{height:50px}#l{margin:0 0 5px 15px}#l td{padding-left:107px}p,table{width:650px;border:0}#l td,#sb,#km{font-size:14px}#l a,#l b{margin-right:1.14em}a{color:#00c}a:active{color:#f60}#hp{position:absolute;margin-left:6px}#lg{margin:-26px 0 -44px}#lk{width:auto;line-height:18px;vertical-align:top}</style></head><body><div id=u></div><center><img src=http://www.baidu.com/img/baidu_logo.gif width=270 height=129 usemap="#mp" id=lg><br><br><br><br><table cellpadding=0 cellspacing=0 id=l><tr><td><div id=m><a onclick=s(this) href=http://news.baidu.com>新 闻</a><b>网 页</b><a onclick=s(this) href=http://tieba.baidu.com>贴 吧</a><a onclick=s(this) href=http://zhidao.baidu.com>知 道</a><a onclick=s(this) href=http://mp3.baidu.com>MP3</a><a onclick=s(this) href=http://image.baidu.com>图 片</a><a onclick=s(this) href=http://video.baidu.com>视 频</a></div></td></tr></table><table cellpadding=0 cellspacing=0 style="margin-left:15px"><tr valign=top><td style="height:62px;padding-left:92px" nowrap><form name=f action=/s><input type=text name=wd id=kw size=42 maxlength=100><script>var w=document.f.wd;w.focus();document.getElementById("u").innerHTML='<a href="http://passport.baidu.com/?login&tpl=mn&u='+escape(location.href)+'">登录</a>';function s(o){if(w.value.length>0){var h=o.href;var q=encodeURIComponent(w.value);if(h.indexOf("q=")!=-1){o.href=h.replace(new RegExp("q=[^&$]*"),"q="+q)}else{o.href+="?q="+q}}};(function(){if(new RegExp("q=([^&]+)").test(location.search)){w.value=decodeURIComponent(RegExp.$1)}})()</script> <input type=submit value=百度一下 id=sb> <span id=hp><a href=/search/jiqiao.html>帮助</a><br><a href=/gaoji/advanced.html>高级</a></span></form></td></tr></table><p id=km><a href=http://hi.baidu.com>空间</a> <a href="http://www.hao123.com" onmousedown="(new Image()).src='http://s.baidu.com/w.gif?fm=index&title=hao123&t='+(new Date().getTime())">hao123</a> | <a href=/more/ style="font-family:宋体">更多>></a></p><p style=height:60px><table cellpadding=0 cellspacing=0 id=lk><tr><td></td></tr></table></p><p style=height:30px><a onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.baidu.com')" href=http://utility.baidu.com/traf/click.php?id=215&url=http://www.baidu.com>把百度设为主页</a></p><p style=height:14px><a href=http://jingjia.baidu.com>企业推广</a> | <a href=http://top.baidu.com>搜索风云榜</a> | <a href=/home.html>关于百度</a> | <a href=http://ir.baidu.com>About Baidu</a></p><p id=b>©2008 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://www.miibeian.gov.cn target=_blank>京ICP证030173号</a> <img src=http://gimg.baidu.com/img/gs.gif></p><map name=mp><area shape=rect coords="43,22,227,91" href=http://hi.baidu.com/baidu/ target=_blank title="点此进入 百度空间"></map></center></body></html><!--b93ac34d0381329f-->