我如何从网站(网址:http ://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player=Hydro698 )获取所有文本并将其放入单行字符串,而不是多行,目前它将有大约 20 行给或取,但我希望它在一行中。
检索文本的代码:
public static void getTextFromURL() {
URL url;
InputStream is = null;
BufferedReader br;
String line;
try {
url = new URL("http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player=Hydro698");
is = url.openStream(); // throws an IOException
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
is.close();
} catch (IOException ioe) {
// nothing to see here
}
}
}
编辑:你不必给我所有的代码,只要指向正确的方向。:)