自己的代码如下:
RandomAccessFile raf = new RandomAccessFile(localFile, "r");
OutputStream out;
//读写操作
..................
out.flush();
raf.close();
out.close();
Log.i(TAG, "befor setDefaultTimeout");
CLogger.i(TAG, "befor setDefaultTimeout");
ftpClient.setDefaultTimeout(1000 * 10);
Log.i(TAG, "befor completePendingCommand");
boolean result = ftpClient.completePendingCommand();
Log.i(TAG, "after completePendingCommand");
从log中看出:
befor completePendingCommand 已打印
after completePendingCommand 未打印
可以判断是completePendingCommand方法一直没有返回。
我看了FtpClient 的源码,发现completePendingCommand做的事比较简单:
public boolean completePendingCommand() throws IOException
{
return FTPReply.isPositiveCompletion(getReply());
}
不知道为何会阻塞。
求高人指点,多谢!!
查了一下,completePendingCommand()会一直在等FTP Server返回226 Transfer complete,但是FTP Server只有在接受到InputStream执行close方法时,才会返回。所以先要执行InputStream的close方法。
没看到你发出具体的ftp命令,completePendingCommand等待服务器返回的数据