[英]how to get all file names of remote server directory using HTTP url in java?
我想通过http URL访问所有文件(名称)。 防爆。 http://app.examle.com/csv/所以我需要评估csv文件中存在的所有文件(名称)
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个文件的数据,但我想读取多个文件请帮助我......!
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 !!");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.