Link to home
Start Free TrialLog in
Avatar of Suppai
Suppai

asked on

Is there a way to set the reading position of a BufferedReader to the first line?

When reading the contents of an URL using a BufferedReader as shown below, how does one reset the reader so that it is at line when finished reading the document?

URL url = new URL(urlString);
BufferedReader urlReader = new BufferedReader(new InputStreamReader(url.openStream()));

Or might I as well just reinitialize the reader, I would think that reinitializing was an inefficient (ressource costly) way to do it?:

BufferedReader urlReader = new BufferedReader(new InputStreamReader(url.openStream()));
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you need to recreate the read to achieve that and yes it is inefficient. It requires you to download the page all over again.
You might want to think about downloading the page and store a copy of the bytes locally if you are going to be wanting to read it again.

Heres an example of one way to store the contents
http://helpdesk.objects.com.au/java/how-to-write-get-response-to-byte-array

Exactly how you implement it depends on your requirements

Avatar of Suppai
Suppai

ASKER

Ok Ill just read again, the mark and reset system seemed to be a bit clumsy.
thats incorrect, it is inefficient.