I need to access a file on an HTTP server and retrieve information from 2 different sites within that file. At this moment I can withdraw from just one. My question is, I can simply do:
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); BufferedReader in2 = new BufferedReader(new InputStreamReader(con.getInputStream()));
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
or do i need to make a new
HttpURLConnection for this?
It makes no sense to create two
BufferedReader s pointing to the same
InputStream . In practice they will be working on the same thing. If you try to read a file using
in and then try to read the same file using
in left off.
That's because classes like
InputStreamReader are just adding behavior to the
InputStream , but the object remains the same.
You need to create two
InputStream s. Or you can on the same
InputStream pull out the two pieces of information you need.