How can u get the Length of a file u are going to download?

HI,

I have another question, is it possible that u can get the length of a file which u are just going to download?

I have the following code example:

url =new URL(dlfrom);<br>

f=new File(url.toURI());<br>

System.out.println(f.length)();<br>

unfortunatly it keeps throwing an exception, please help.

[427 byte] By [betlora] at [2007-10-2 20:29:09]
# 1
RTFM http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLConnection.html#getContentLength()
tjacobs01a at 2007-7-13 23:12:05 > top of Java-index,Core,Core APIs...
# 2

> RTFM

>

> http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLCo

> nnection.html#getContentLength()

I tried to apply your sollution, but it is allways returning -1, so what should I do now, is there any possebility still to get the length of the object, because i thought of doing something similar as a tool to download stuff

betlora at 2007-7-13 23:12:05 > top of Java-index,Core,Core APIs...
# 3
If it isn't there in the Content-Length it isn't there at all. Why do you need to know?
ejpa at 2007-7-13 23:12:05 > top of Java-index,Core,Core APIs...
# 4
I need it to display how much percent of the file are allready downloaded.
betlora at 2007-7-13 23:12:05 > top of Java-index,Core,Core APIs...
# 5
It's impossible to know file size if server did not pass it to client. IMPOSSIBLE. You should design your application with ability to handle such situations and show bytes not percents during downloading or something like this.
Michael.Nazarov@sun.coma at 2007-7-13 23:12:05 > top of Java-index,Core,Core APIs...