我有一個問題給大家。我追求速度,而且我需要使用這種方法,所以這種方法效率越高越好。Java - 從網站加載文本的最有效方式?
我的代碼:
private void method(final String name) {
final URL url = new URL("http://www.somewebsite.com/blah.php?name=" + name);
final BufferedReader in = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()));
final String totalText = in.readLine();
in.close();
//other stuff using the totalText variable
}
這種方法工作,但我問是否有這個工作一個更有效的方式。
重要事項關於我讀的代碼:
- 從網站上整個源代碼是唯一一個線長。
- 還有沒有帶有網站代碼的HTML標籤。這全是原始文字。
我不知道......會'totalText = in.readLine();'工作?然後,我將刪除'inputLine'變量和'while'循環? – Confiqure 2012-07-29 18:43:31
如果您確定它始終是1行,是的。但不應該加快這一點 – 2012-07-29 18:45:45
大家:我修改了我的代碼。 – Confiqure 2012-07-29 18:46:27