我已经能够实现文件的下载 但是文件总是自动下载到工程目录下 如何下载到指定目录呢?比如我希望他能够下载到"D:/"  知道的请指点下~

解决方案 »

  1.   

    FtpClient   ftp   =   new   FtpClient(host);   
     ftp.login(username,   password);   
      ftp.binary();   
      ftp.cd(path);                         
                       while((s=dr.readLine())!=null)   {          
                           System.out.println(a(s));                             getfile   =   ftp.get(a(s));         
                                str   =   ftp.getResponseString   ();   
                                System.out.println(str);                         
                                                                         
                                FileOutputStream   output   =   new   FileOutputStream   (new   File   (a(s)));             
                                while(   true   )     
                                {     
                                      int   y   =   getfile.read();                               
                                      if(   y   ==   -1   )   break;     
                                      else     
                                      {   
                                              output.write   ((byte)y);   
                                              output.flush();   
                                      }   
                                                                                    
                                }                             
                                getfile.close();   
                                output.close   ();   
    }public   static   String   a(String   s)   {       
          String   s1="";   
          StringTokenizer   st=new   StringTokenizer(s,"   ");   
          s1=st.nextToken();   
          
          while(st.hasMoreTokens())   
          { s=st.nextToken(); 
                     }
        if (s1.indexOf("-")!=-1) 
              s2=s ;
        else
             s2 = null;
      
          return  s1.indexOf("-")==-1?"Folder:"+s:"File:"+s;      }
      

  2.   


         String server=Server;
         String user=User;
         String password=Pass;
         String path=FtpPath;     try {
          FtpClient ftpClient = new FtpClient();
          //创建FtpClient对象
          ftpClient.openServer(server,this.Port);
          //连接FTP服务器
          ftpClient.login(user, password);
         //登录FTP服务器
          if (path.length() != 0) ftpClient.cd(path);      //下载一个文件
          ftpClient.binary();      TelnetInputStream is = ftpClient.get(FileName);      File file_out = new File(SavePath+FileName);
          FileOutputStream os = new FileOutputStream(file_out);
          byte[] bytes = new byte[1024];
          int c;
          while ( (c = is.read(bytes)) != -1) {
            os.write(bytes, 0, c);
          }
          is.close();
          os.close();      ftpClient.closeServer(); //退出FTP服务器
        } catch (Exception ex) {
        }
      

  3.   

    谢谢楼上的 我已经实现下载了
     我是希望能把文件下载到本地计算机指定的目录中去 比如下到“D:/” 
    楼上的和我自己的代码都只能够实现把文件下载到我所建立的这个JAVA项目中的文件夹里 我不想让他那么死 想灵活一些 让他下载入我指定的文件  如何实现呢?
      

  4.   

    晕,楼主仔细看看SavePath+FileName,就是你指定的目录呀
      

  5.   

    运行下来还是下载到了项目目录 没有下到目标文件夹~ 
     getfile   =   ftp.get(filename3);         
                                str   =   ftp.getResponseString   ();   
                                System.out.println(str);                         
                                   File file_out = new File("D:/"+filename3);
                                   FileOutputStream os = new FileOutputStream(file_out);                                       
                             //   FileOutputStream   output   =   new   FileOutputStream   (new   File   (filename3));             
                                while(   true   )     
                                {     
                                      int   y   =   getfile.read();                               
                                      if(   y   ==   -1   )   break;     
                                      else     
                                      {   
                                              os.write ((byte)y);   
                                              os.flush();
                                              //output.flush();   
                                      }   
                                                                                    
                                }                             
                                getfile.close();   
                               os.close   ();
    楼上帮我看下 我哪里写错了么?