我看过很多例子并试图理解我做错了什么但没有成功,也许你可以帮助我。它总是停在第二个文件上,但第一个文件只是在 c:\ 上以 0kb 大小装箱。files_server.get(i) 是包含我希望下载的所有文件的 ArrayList。
我的代码:
public FTPConnection() {
StartD std = new StartD();
std.start();
}
class StartD extends Thread{
@Override
public void run()
{
for (int i = 0; i < files_server.size(); i++) {
err = ftpDownload(files_server.get(i), "C:/"+ files_server.get(i));
if (!err)
{
System.out.println("Error in download, breaking");
break;
}
}
}
public boolean ftpDownload(String srcFilePath, String desFilePath)
{
try {
FileOutputStream desFileStream = new FileOutputStream(desFilePath);
InputStream input = mFTPClient.retrieveFileStream(srcFilePath);
byte[] data = new byte[1024];
int count;
while ((count = input.read(data)) != -1)
{
desFileStream.write(data, 0, count);
}
desFileStream.close();
} catch (Exception e) {
return false;
}
return true;
}}
如果我使用功能:
public boolean ftpDownload(String srcFilePath, String desFilePath) {
boolean status = false;
try {
FileOutputStream desFileStream = new FileOutputStream(desFilePath);
status = mFTPClient.retrieveFile(srcFilePath, desFileStream);
desFileStream.close();
return status;
} catch (Exception e) {
}
return status;
}
相反,一切正常,但我无法监控文件下载进度。