hi everyone,
I don't know much about about other types of downloads except for ftp downloads. By the way you can use the below function as a way to get file sizes
Code:
import java.net.*;
import java.lang.reflect.*;
import sun.net.ftp.*;
import sun.net.*;
int getfilesize(FtpClient client, String filename){
//This function tries to get the file size of the currently
//uploaded or downloaded file
String str = "", token;
int c, index = 0;
char ch;
try
{
//The try statement is to try to catch any errors thrown by
//the Java input and output
TelnetInputStream lst = client.list();
filename = filename.toLowerCase();
while(true)
{
c = lst.read();
ch = (char) c;
if((c < 0) || (ch == '\n'))
{
str = str.toLowerCase();
if(str.indexOf(filename) >= 0)
{
StringTokenizer tk = new StringTokenizer(str);
while(tk.hasMoreTokens())
{
token = tk.nextToken();
if(index == 4)
{
//The try statement is to try to catch any errors thrown by
//the Java input and output
try
{
return Integer.parseInt(token);
}
//The catch statement is to try to catch any errors
//thrown by the Java input and output
//by using the NumberFormatException constant
catch(NumberFormatException e)
{
return -1;
}
}
index++;
}
str = "";
}
if(c <= 0)
{
break;
}
str += ch;
}
return -1;
}
}
//The catch statement is to try to catch any errors
//thrown by the Java input and output
//by using the Exception constant
catch(Exception e1)
{
System.out.println("File size unknown");
}
return -1;
} I tried the function and it works and i hope it helps you. The function returns the current downloaded size of the file.
Please let me know what think of this function
Yours Sincerely
Richard West