In your example, you have assigned the input stream to the variable "is". If the variable "is" is NULL, that means it does not point to an input stream object. Therefor if you try to call a method on a variable that does not point to an object, you will get a NullPointerException.
This is the reason to test if the variable is NULL before trying to call a method on it. An exception may have been thrown while the input stream was being created so the input stream object was never assigned to the "is" variable.