Reputation: 3805
I was trying to get some HTML by URL and put it into String. This is my effort:
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);
}
}
As I said I want to put it to inputLine
, but it returns NULL
.
What's wrong?
Upvotes: 1
Views: 80
Reputation: 33327
Use a StringBuilder
for string concatenation. The loop should look like this:
String inputLine;
StringBuilder sb = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine).append("\n");
}
System.out.println(sb);
Upvotes: 3