The code pasted below was taken from Javadocs on HttpURLConnection.
I get the following error:
readStream(in)   ...as there is no such method.
I see this same thing in the Class Overview for URLConnection at URLConnection.getInputStream
Where is readStream? The code snippet is provided below:
 URL url = new URL("http://www.android.com/");        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();        try      {              InputStream in = new BufferedInputStream(urlConnection.getInputStream());              readStream(in);  <-----NO SUCH METHOD     }     finally      {              urlConnection.disconnect();        }  
                InputStream. read() method reads the next byte of the data from the the input stream and returns int in the range of 0 to 255. If no byte is available because the end of the stream has been reached, the returned value is -1.
Java FileInputStream constructorsFileInputStream(File file) — creates a file input stream to read from a File object. FileInputStream(String name) — creates a file input stream to read from the specified file name. FileInputStream(FileDescriptor fdObj) — creates a file input read from the specified file descriptor.
InputStream , represents an ordered stream of bytes. In other words, you can read data from a Java InputStream as an ordered sequence of bytes. This is useful when reading data from a file, or received over the network.
Try with this code:
InputStream in = address.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder result = new StringBuilder(); String line; while((line = reader.readLine()) != null) {     result.append(line); } System.out.println(result.toString()); 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With