您的问题(好吧,在我们摆脱
.和之后
..,您已经解决了二进制问题),这是您在调用之前执行递归步骤
newDir.mkdirs()。
所以假设你有一棵像
...someDir . .. someFile.txtsomeOtherDir . ..someOtherFile.png
您要做的是跳过点文件,看到它
someDir是目录,然后立即进入其中,跳过其点文件,然后查看
someFile.txt并处理它。您尚未在
someDir本地创建,因此会出现异常。
您的异常处理程序不会停止执行,因此控制权返回到递归的上层。此时,它将创建目录。
因此,下次运行程序时,本地
someDir目录已从上一次运行中创建,您不会发现任何问题。
基本上,您应该将代码更改为:
if (file.isDirectory()) { // Change working Directory to this directory. ftpClient.changeWorkingDirectory(file.getName()); // Create the directory locally - in the right place File newDir = new File (base + "/" + ftpClient.printWorkingDirectory()); newDir.mkdirs(); // Recursive call to this method. download(ftpClient.printWorkingDirectory(), base); // Come back out to the parent level. ftpClient.changeToParentDirectory(); }


