• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Size of the URL file

 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have made a Servlet that downloads a file from the remote host.
Input parameter to my Servlet is the absolute URL of the file.
It works, but I can't get the file size of the file I'm trying to download.
How I can obtain that information?

Here is a small excerpt from my code:

URL mp3_url = new URL(fileName);//fileName = absolute URL
InputStream input = mp3_url.openStream();
...
 
Bhanu
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the protocol you are using as part of the absolute URL?
If that is HTTP then you can try to open the connection using URL and you would get HTTPURLConnection object...using that you can find the content legnth....
I don't think using Inputstream you can get the size of the whole content before reading the stream completely.
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have tried that too. But, there is no getSize() or length() methods. In fact, in order to get the size of the file, I have to read all the bytes and than count them. It is possible, but I want to do something different. I want to send what I have read immediately to the response (no cashing on the server).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic