FTP获取文件列表出错,帮忙看看问题在哪里 ?

public static boolean downFile(String url,
int port,
String username,
String password,
String remotePath,
String fileName,
String localPath
)
{
boolean success = false;
FTPClient ftp = new FTPClient();
try
{
int reply;
ftp.connect(url, port);
ftp.login(username, password);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply))
{
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(remotePath);

        for (FTPFile ff : fs)
        {
            if (ff.getName().equals(fileName))
            {
                File localFile = new File(localPath + "/" + ff.getName());
                OutputStream is = new FileOutputStream(localFile);
                ftp.retrieveFile(ff.getName(), is);
                is.close();
            }
        }

        ftp.logout();
        success = true;
    } catch (IOException e)
    {
        e.printStackTrace();
    } finally
    {
        if (ftp.isConnected())
        {
            try
            {
                ftp.disconnect();
            } catch (IOException ioe)
            {
            }
        }
    }
    return success;
}


FTPFile[] fs = ftp.listFiles();//到这里的时候总是报
        //org.eclipse.debug.core.DebugException:
        //com.sun.jdi.ClassNotLoadedException: 
        //Type has not been loaded occurred while retrieving component type of array.

导入 org.apache.commons.net.ftp 包,import 它。

http://stackoverflow.com/questions/1367730/how-do-i-deal-with-a-classnotloadedexception-while-debugging

应该不是import的问题,错误是指FTPFile[] 这个数组类型还没装载。
据说这个可能是debugger 的bug,你试一下刷新工程并重新编译一下。

再不行的话,先调用个Class.forName()方法,强制jvm装载那个数组类型。

我在win10上遇到的问题,关闭win10防火墙就搞定了

防火墙关闭之后就没有这个异常了,后面遇到一个新的情况 ftpClient.enterLocalPassiveMode(); 这句话不调用没法下载文件,会导致ftpClient.listFiles()总是为0