• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

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()));
0
Suppai
Asked:
Suppai
  • 2
1 Solution
 
CEHJCommented:
It's not really inefficient, but you could use mark and reset. Since the mark point could be difficult to determine though, it's better to just read it again.
0
 
objectsCommented:
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

0
 
SuppaiAuthor Commented:
Ok Ill just read again, the mark and reset system seemed to be a bit clumsy.
0
 
objectsCommented:
thats incorrect, it is inefficient.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now