2017-02-24 301 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庫,改成服務器配置文件中的變化顯示聽者 –

相關問題