Firstly, I suspect that's not your code - or it would throw a NullPointerException
. I suspect you've actually got:
s = s + strLine;
After that, it's very simple - concatenating any string with a null
String reference will give you null
:
String x = null;
String y = x + "a";
System.out.println(y); // nulla
From section 15.18.1 of the JLS (string concatenation):
If only one operand expression is of type String, then string conversion (§5.1.11) is performed on the other operand to produce a string at run time.
Then from section 5.1.11:
If the reference is null, it is converted to the string "null" (four ASCII characters n, u, l, l).
Note that your code is extremely inefficient at the moment - you should be using a StringBuilder
.