Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I read in more than a byte at a time into InputStream ?

Status
Not open for further replies.

UncleScooby

Programmer
Jun 1, 2001
30
0
0
GB

I want to read in a whole web page so I can search for some product prices matches.

At the moment I am using the .read method from the InputStream class but this only reads in a byte at a time.

Is there a better/quicker way to read in all the page so I can then use some string manipulation to locate the product prices I am interested in.

Any info appreciated.

US.
 
The read() method of InputStream can read more than one byte at a time. Take a look at the API.

Anyway, I'd user a BufferedInputStream.

Cheers,

Dian
 
I take it that you are using the HttpUrlConnection class to download the web page.
This class has a method getContentLength() - so then you can use :

Code:
HttpUrlConnection huc ...
int len = huc.getContentLength();
byte[] data = new byte[len];
if (len > 0) {
  DataInputStream dis = new DataInputStream(huc.getInputStream());
  dis.readFully(data);
  dis.close();
}

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top