posted 18 years ago
Well, you didn't quite answer my question, but I'll assume that you're using plain Sockets to connect to a Web server to download the file.
If you use HTTP 1.0 commands to fetch the file, you'll get a "Content-Length:" header which you can parse to get the length of the file -- i.e., like the below. The line "GET / HTTP/1.0" is the key thing you have to send; the Content-Length header will come back and you can parse it.
It's a lot easier to use URLConnection, though!
$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0
HTTP/1.1 200 OK
Date: Wed, 25 Feb 2004 22:13:40 GMT
Server: Apache/2.0.48 (Unix) DAV/2 SVN/1.0.0
Last-Modified: Mon, 23 Feb 2004 21:22:09 GMT
ETag: "50421c-ae5-a0490240"
Accept-Ranges: bytes
Content-Length: 2789
Connection: close
Content-Type: text/html; charset=ISO-8859-1
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>