Showing posts with label InputStream. Show all posts
Showing posts with label InputStream. Show all posts

How to Get Readable InputStream from URLConnection

public InputStream getInputStream () was added in API level 1
Returns an InputStream for reading data from the resource pointed by this URLConnection. It throws an UnknownServiceException by default. This method must be overridden by its subclasses.
Returns: the InputStream to read data from.
Throws: IOException - if no InputStream could be created.

1. Check if Response Code is OK


3. Add the below line in the try/catch created in step #1.

myInputStream = myHttpURLConnection.getInputStream();

4. Compile and run!

Resources:
http://developer.android.com/reference/java/net/URLConnection.html#getInputStream()