如题,假设是apache服务器上的某个路径,用Java如何获取该路径下的所有文件夹名?

解决方案 »

  1.   

    用java代码怎么实现,有源码吗?
      

  2.   

    你的java是在服务器还是客户端,服务器,那个就不消说了,File.list系列方法,配合过滤器客户端的,需要httpclient,解析apache的directory index页面。当前,前提是你apache开启了autoindex。
      

  3.   

    用java调用命令行吧,硬来效率太低,Apache Commons CLI 
      

  4.   

    可以用ftpClient:
     public FtpClientUtil(String server,int port,String userName,String userPassword)
     {
      this.server=server;
      this.port=port;
      this.userName=userName;
      this.userPassword=userPassword;
     }
     /**
      * 链接到服务器
      * @return
      */
     public boolean open()
     {
      if(ftpClient!=null&&ftpClient.serverIsOpen())
       return true;
      try
      {
          ftpClient= new FtpClient();
          ftpClient.openServer(server,port);
          ftpClient.login(userName, userPassword);
          ftpClient.binary();
          return true;
      }
      catch(Exception e)
      {
       e.printStackTrace();
       ftpClient=null;
       return false;
      }
     }/**
      * 返回FTP目录下的文件列表
      * @param ftpDirectory
      * @return
      */
      public List<String> getFileNameList(String ftpDirectory) 
      { 
         List<String> list = new ArrayList<String>(); 
         if(!open())
       return list;
         try  
         { 
            DataInputStream dis = new  DataInputStream(ftpClient.nameList(ftpDirectory)); 
            String filename = ""; 
            while((filename=dis.readLine())!=null)   
            {
              list.add(filename);         
            }   
         } catch (Exception e)  
         { 
            e.printStackTrace(); 
         } 
         return list; 
      }