在files = ftp.listFiles("upload");这一行报错:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/oro/text/regex/MalformedPatternException在网上查到的有关信息显示这一般是由于项目路径不包含引入的包,但是这里明显不是这个问题:如果是路径问题,那么前面的listNames()等方法也不可用,可是偏偏只是遍历文件不可用,这是怎么回事呢?        FTPClient ftp = null;
        try {
            ftp = new FTPClient();
            try {
                ftp.connect("10.4.192.1");
                ftp.login("t", "ddd");
            } catch (SocketException ex) {
                ex.printStackTrace();
            }
            System.out.println("连接到 10.4.192.1.");
            System.out.print(ftp.getReplyString());
            int reply = ftp.getReplyCode();
            if(!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.err.println("FTP server refused connection.");
                System.exit(1);
            }
            ftp.changeWorkingDirectory("upload");
            
            String[] names = ftp.listNames();
            for (int i=0; i<names.length; i++) {
                System.out.println(cn.getStr(names[i]));
            }
            System.out.println(ftp.listHelp());
                        FTPFile[] files;
            files = ftp.listFiles("upload");
            for (int i = 0; i < files.length; i++) {
                System.out.println(files[i].getName());
            }
            
            
            
            ftp.logout();
        }catch (IOException ex) {
                ex.printStackTrace();
        }
        finally {
            if(ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch(IOException ioe) {
                    // do nothing
                }
            }
        }

解决方案 »

  1.   

    是否commons-net要依赖某些别的包?
      

  2.   

    Q: I see the following exception thrown when calling FTPClient.listFiles() java.lang.NoClassDefFoundError: org/apache/oro/text/regex/MalformedPatternException. What is this about? A: the library jakarta-oro.jar is required to be on your classpath in order to run the all the listFiles() methods and is listed as a dependency of commons-net. Get it from  http://jakarta.apache.org/site/downloads/downloads_oro.cgi 
      

  3.   

    下了jakarta-oro.jar后解决了,谢谢!