1

我试图通过 URL 获取一些 HTML 并将其放入 String。这是我的努力:

public class 

    Bank {
        public static void main(String[] args) throws IOException {
            URL hh = new URL("https://m.hh.ru/");
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(hh.openStream()));

            String inputLine;
            while ((inputLine = in.readLine()) != null) {

                inputLine.concat(inputLine);//returns null. WTF?
                System.out.println(inputLine);

            }
            in.close();
            System.out.println(inputLine);
        }
        }

正如我所说我想把它inputLine,但它返回NULL。怎么了?

4

1 回答 1

3

使用 aStringBuilder进行字符串连接。循环应如下所示:

String inputLine;
StringBuilder sb = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
    sb.append(inputLine).append("\n");
}
System.out.println(sb);
于 2013-08-24T16:47:30.560 回答