Skip to Content
0
Former Member
Nov 23, 2005 at 05:33 AM

Problem reading data from url

49 Views

Hi,

I am facing a problem, trying to read the data from a url. I open a connection and get an input stream of the url. When I read the input stream into a byte[], only part of the data is read, other characters become junk.

This is the code I use

URL url = new URL(uri);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.connect();

byte[] file = new byte[conn.getContentLength()];

int size = in.read( file, 0, conn.getContentLength() );

The size (no of bytes read) is way less than the length of the stream. Please help...

Regards,

Guru