This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Connection refused normally means there was nothing listening on the port you tried to connect to, or possibly, that you tried to connect with the wrong protocol (i.e. http where https was required). Check your url and whether you should maybe be using HttpsUrlConnection rather than HttpUrlConnection.
Ananth, Your program has 2 issues: unable to connect to URL, and incorrect logic to read data into a buffer. I have modified your program and tested with localhost. Note: use of Reader to read data directly as char instead of byte