我想获得ftp服务器上指定文件的大小
以及下载过程中文件的已完成下载的大小
求教
这个是我写的方法
code::
public static boolean downLoadFtp(String ftpServerIp, String ftpUser,
String ftpPassWord, String url, String filePath, String fileName) {
try {
FtpClient fc = new FtpClient(ftpServerIp);
fc.login(ftpUser, ftpPassWord);
fc.binary();
int ch;
int filesize = 0;
String fileStr = filePath + fileName;
File filename = new File(fileStr);
System.out.println("C:: download 89 filename size :: "+filename.toString());
if (filename.exists()) {//如果存在就直接覆盖
filename.createNewFile();
//return false;
}
if (!filename.exists()) {
if (filename.createNewFile()) {
System.out.println("File is created successfully!");
}
}
RandomAccessFile getFile = new RandomAccessFile(fileStr, "rw");
getFile.seek(0);
// url="/FTPTest1.txt";
TelnetInputStream fget = fc.get(fileName);
DataInputStream puts = new DataInputStream(fget);
while ((ch = puts.read()) >= 0) {
filesize = filesize + ch;
getFile.write(ch);
}
System.out.println("C:: download 96 filesize : : "
+ filesize);
fget.close();
getFile.close();
fc.closeServer();
} catch (IOException ex) {
ex.printStackTrace();
}
return true;
}
我应该如何在下载之前获得文件的大小啊
以及在现在过程中下载文件的大小···
谢谢··
我想做一个进度条····
可是没有办法获得文件的大小····
谢谢····
2009年3月18日 17:07