I am using a small code for downloading a web page content. But its working very slow. When I open same web page using my mozilla browser it hardly takes 2-3 seconds but when I use my Java code it takes 55-60 seconds for the same page (Just for HTML, no images). What could be the reason.
This is some fairly inefficient code. While you do use a BufferedInputStream, which is good, you read it one. byte. at. a. time. Which is not good.
Furthermore, you have a Reader, which does character conversion, but you since you are reading it by the byte, you have to do a second character conversion (the cast of 'c' to char).
Also note that String.valueOf uses the platform default encoding for the conversion - which may not be the right one. You need to check the Content-Type header of the response to find out which encoding it's in, and then use that for your byte-to-String conversion.
Hey, I wrote that FAQ
I'd recommend following the link at the bottom of the FAQ to the Java Platform Performance book. There' s more than one way to buffer IO and some methods make more sense in some situations.