ftp下载cglib文件处理

ftp下载cglib文件处理

    最近接收一个遗留项目,用的是flex和java,后台用的是mybatis和spring。在测试时发现下载有问题,结果花了一两天时间才将问题解决,下面将解决过程中碰到的问题和解决的思路贴出来: 因为项目做出来有段时间了,当初用的是sun.net.ftp.FtpClient这个类,这个类本身就存在问题,而且java api文档中无法查询。并且是jdk1.6的版本,导致放在jre1.7上时保存,后来改成jre1.6问题才解决,但是仍然无法下载,一直报异常“Source not found for $$FastClassByCGLIB$$7782d62a.invoke(int, Object, Object[]) line: not available”。让人很纠结,硬是没有找到原因所在,网上有的说是sql语句错了,有的说是jar包的问题,有的说是反射或cglib的问题等等,但是一一测试仍然没有解决,因为之前有人说这个功能是好的,所以就没有打算换方法,后来实在不行,网上也有人建议用apache的org.apache.commons.net.ftp.FTPClient类,就换成了FTPClient。结果居然好用了: 代码如下:
Java代码 复制代码 收藏代码
  1. publicstaticboolean downFile(List<String> directoryList, 
  2.             String targetPath) {   
  3.              
  4.             boolean success = false;   
  5.             for (String directoryString : directoryList) { 
  6.                 String fileName = directoryString.substring(directoryString 
  7.                         .lastIndexOf("/") + 1); 
  8.                 String remotePath = directoryString.substring(1, directoryString 
  9.                         .lastIndexOf("/")); 
  10.                  FTPClient ftp = new FTPClient();   
  11.                     try {   
  12.                         int reply;   
  13.                         ftp.connect(ftpIP);   
  14.                         ftp.login(username, password);//登录   
  15.                         reply = ftp.getReplyCode();   
  16.                         if (!FTPReply.isPositiveCompletion(reply)) {   
  17.                             ftp.disconnect();   
  18.                             return success;   
  19.                         }   
  20.                         ftp.changeWorkingDirectory(remotePath);//转移到FTP服务器目录   
  21.                         FTPFile[] fs = ftp.listFiles();   
  22.                         for(FTPFile ff:fs){   
  23.                             if(ff.getName().equals(fileName)){   
  24.                                    
  25.                                 File localFile = new File(targetPath+"/"); 
  26.                                 if (!localFile.exists()) { 
  27.                                     localFile.mkdirs(); 
  28.                                 } 
  29.                                 OutputStream is = new FileOutputStream(localFile+"/"+ff.getName());   
  30.                                 ftp.retrieveFile(ff.getName(), is);   
  31.                                 is.close();   
  32.                             }   
  33.                         }   
  34.                            
  35.                         ftp.logout();   
  36.                         success = true;   
  37.                     } catch (IOException e) {   
  38.                         e.printStackTrace();   
  39.                     } finally {   
  40.                         if (ftp.isConnected()) {   
  41.                             try {   
  42.                                 ftp.disconnect();   
  43.                             } catch (IOException ioe) {   
  44.                             }   
  45.                         }   
  46.                     }   
  47.             } 
  48.             return success;   
  49.         } 

posted on 2014-02-11 10:07  jackvc  阅读(197)  评论(0编辑  收藏  举报

导航