Originally Posted by
samvenkatram
Yeah, it's kind of difficult to get the hierarchy straight...
Two problems with the second statement above:
- InputStreamReader constructor needs an InputStream argument, not a URL.
- Declaring an InputStream object and setting it equal to something obtained from an InputStreamReader constructor does not compute.
Things go downhill from there:
Originally Posted by
samvenkatram
Some problems with this
- The BufferedReader constructor takes an Reader as argument not an InputStream. (An InputStreamReader object would be cool here.)
- BufferedReader class does not have an openStream() method.
- The assignment statement doe not compute. (Looks to me like it is assigning a stream to a BufferedReader object. I'm not sure how it looks to a compiler.)
One possible approach: Four statements:
- Declare a new URL object, url, with a String argument for the constructor. Yours is OK for this step.
- Declare an InputStream object and set it equal to url.openStream() (Do not use new here: You already have a URL object.)
- Declare a new InputStreamReader object with your InputStream object as the argument for the constructor
- Declare a new BufferedReader object with your inputStreamReader object as the argument for the constructor.
You can shorten the number of lines of Java (by putting some of the
new stuff in the arguments for some of the constructors), but start with something that works and make it more elegant if you feel the need for obfuscation.
Cheers!
Z