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?
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.
Thanks,<br />Bhanu<br />SCEA Step-I<br />SCBCD for J2EE 1.3<br />SCJP1.4
Joined: Jan 15, 2002
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).