新手求教,不明白为什么不能把全部数据写进去。

totomas 2017-11-02 09:30:31
import java.net.*;
import java.io.*;


public class TestUrlConnection {

public static void main(String[] args) {
BufferedReader reader = null;
HttpURLConnection connection = null;
try {
// 新建一个URL对象,指定到请求的url.
URL url = new URL("http://quote.tool.hexun.com/hqzx/quote.aspx?type=2&market=0&sorttype=3&updown=up&page=1&count=20000");
connection = (HttpURLConnection) url.openConnection();

File f = new File("stock.txt");
FileOutputStream fOut = new FileOutputStream(f);
PrintWriter p = new PrintWriter(fOut);



reader = new BufferedReader(new InputStreamReader(connection
.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
//System.out.println(line);
line=line.replace("dataArr = [", "");
line=line.replace("[", "");
line=line.replace("],", "");

p.println(line);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
connection.disconnect();
}
}

}
...全文
193 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
代码间的舞者 2017-11-05
  • 打赏
  • 举报
回复
这是网络爬虫的代码?楼主想问为什么读一个网页还要用while循环?我也想知道。

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧