以下のコードを使用して、Javaでhtmlファイルをダウンロードしています。私がここでやっていることは、ウェブサイトへの入力ストリームを開いていることです。その後、コンテンツを読み込んで、その html ファイルの行数を出力しようとしています (実際の問題に役立つことをしています:p)。コードを実行すると、出力が異なります。
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(
"URL");
HttpResponse response;
try {
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
Scanner sc = new Scanner(new BufferedReader(
new InputStreamReader(instream, "UTF-8")));
int count = 0;
while (sc.hasNextLine()) {
count++;
sc.nextLine();
}
System.out.println(count);
}
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} finally {
}
ダウンロードしている Web ページが大きすぎるためでしょうか?