【问题标题】:DebugException in apache-commons-netapache-commons-net 中的 DebugException
【发布时间】:2014-12-10 04:29:11
【问题描述】:

当我尝试使用ftpClient.listFiles("folder"); 列出我所在位置的文件时,它会显示

org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException: Type has not been loaded occurred while retrieving component type of array.

谁能指导我做错了什么。

我用apache-commons-net-3.3

我的代码是

FTPClientConfig ftpClientConfig = new FTPClientConfig(FTPClientConfig.SYST_NT);
FTPClient ftpClient = new FTPClient();
ftpClient.configure(ftpClientConfig);
ftpClient.connect(hostName, Integer.valueOf(portNumber));
ftpClient.enterLocalPassiveMode();
ftpClient.login(username, password);

// Error throws here
FTPFile[] files = ftpClient.listFiles("folder");

【问题讨论】:

    标签: java apache-commons-net


    【解决方案1】:

    当用户输入错误或加密的用户名或密码时会引发此异常。

    Apache 没有抛出正确的异常。

    【讨论】:

      【解决方案2】:
         public void ConnectToFtp(String serverAdd,String username,String password){
      
             try {    
      
                 ftpclient.connect(serverAdd);
      
                 boolean login  =    ftpclient.login(username,password);
      
                    reply = ftpclient.getReplyCode();
      
      
                    if(FTPReply.isPositiveCompletion(reply)){
      
                        System.out.println("Connected Success");
      
      
                    }else {
      
                        System.out.println("Connection Failed");
      
                        ftpclient.disconnect();
      
                    }
                    if (login) {  
                          System.out.println("Connection established...");  
      
      
                          FTPFile[] ftpFiles = ftpclient.listFiles();
                          for (FTPFile ftpFile : ftpFiles) {
      
                              if (ftpFile.getType() == FTPFile.DIRECTORY_TYPE) {
                                  System.out.printf("FTPFile: %s; %s%n",
                                      ftpFile.getName(),
                                      FileUtils.byteCountToDisplaySize(ftpFile.getSize()));
                              }
                          }
                      }
               boolean logout = ftpclient.logout();  
                    if (logout) {  
                     System.out.println("Connection close...");  
                    }  else {  
                    System.out.println("Connection fail...");  
                   }  
      
               } catch (SocketException ex) {
      
                 ex.printStackTrace();
      
             } catch (IOException ex) {
      
                 ex.printStackTrace();
                 } finally {  
                 try {  
                  ftpclient.disconnect();  
                 } catch (IOException e) {  
                  e.printStackTrace();  
                   }  
                }  
             }
          }
      

      【讨论】:

        猜你喜欢
        • 2023-04-05
        • 2015-01-17
        • 1970-01-01
        • 1970-01-01
        • 2012-12-27
        • 2014-03-26
        • 2013-06-17
        • 1970-01-01
        • 2012-03-21
        相关资源
        最近更新 更多