2017-02-24 299 views
1

我想通过http URL访问所有文件(名称)。例如, http://app.examle.com/csv/ 所以我需要能够评估的所有文件(名称)出现在CSV文件如何在java中使用HTTP url获取远程服务器目录的所有文件名?

 headerBaseUrl="http://app.examle.com/csv/stock.csv"; 
    URL br = new URL(headerBaseUrl); 
     bufferedReader = new BufferedReader(
       new InputStreamReader(br.openStream())); 
     // Create List for holding Employee objects 
     List<BranchWiseStock> branchWiseStock = new ArrayList<BranchWiseStock>(); 

     String line = ""; 
     // Read to skip the header 
     bufferedReader.readLine(); 
     // Reading from the second line 
     while ((line = bufferedReader.readLine()) != null) { 
      String[] stockDetails = line.split(COMMA_DELIMITER); 
      if (stockDetails.length > 0) { 
        System.out.println(" data "+stockDetails); 
       } 
      } 

在这里,我可以得到1个文件轻松 的数据,但我想读取多个文件 请帮我...!

+0

请新增你做了什么至今 –

+1

非常感谢的答复 – Prashant

回答

0
public class FTPDownloadFileDemo { 
    public static void main(String args[]) { 

     String hostname = "XXX"; 
     String username = "XXX"; 
     String password = "XXX"; 
     //Single file download 
     // String copyFrom = "serverFolderPath/"; 
     // String copyTo = "localPath/";  
     JSch jsch = new JSch(); 
     Session session = null; 
     System.out.println("Trying to connect....."); 
     try { 
      session = jsch.getSession(username, hostname, 22); 
      java.util.Properties config = new java.util.Properties(); 
      config.put("StrictHostKeyChecking", "no"); 

      session.setConfig(config); 
      session.setPassword(password); 
      session.connect(); 
      Channel channel = session.openChannel("sftp"); 
      channel.connect(); 
      ChannelSftp sftpChannel = (ChannelSftp) channel; 

      sftpChannel.cd("serverFolderPath/csv/"); 
      Vector<ChannelSftp.LsEntry> list = sftpChannel.ls("*"); 
      for(ChannelSftp.LsEntry entry : list) { 
       System.out.println("Name :"+entry.getFilename()); 
      } 
      // sftpChannel.get(copyFrom, copyTo); 
      sftpChannel.exit(); 
      session.disconnect(); 
     } catch (JSchException e) { 
      e.printStackTrace(); 
     } catch (SftpException e) { 
      e.printStackTrace(); 
     } 
     System.out.println("Done !!"); 
    } 
} 
+0

使用JSch库,改成服务器配置文件中的变化显示听者 –

相关问题