Win a copy of Penetration Testing Basics this week in the Security forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URL Connection Stream

Sreenath Madasu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!
I have a question regarding URl and URL COnnection. What is the fifference between URLConnection.getInputStream and URL.openStream? They should be the same right? In our application we are opening a URLCOnnection from a URL object to get contenttype, length etc. Then using the same URLObject we are opening stream with openstream and writing out to another stream. Sometimes the length returned by URLConnection is different from the total bytes read from URL.openStream() method. Why is that?

Here are the steps again
1) Create URL Object -- say URLObj1

2) Create URLCOnnection --- URLCon1

3) get contentlength from URLCon1 -- contentLength1

4) OpenStream from URLObj1 as UrlObj1.openStream()

5) Write the above to another stream and count the total bytes read. -- totbytes

6) Sometimes totbytes is different from contentLength1

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic