新手求教,不明白为什么不能把全部数据写进去。
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();
}
}
}