![](/img/trans.png)
[英]Java: Downloading .Zip files from an FTP and extracting the contents without saving the files on local system
[英]Get ZIP first entry name from remote FTP Server without downloading the zip using Java 8+
我做了以下工作,據我所知,沒有其他答案。
示例輸入( “ftp-folder/input.txt” ):
public String getZipFirstEntryName(final String remotePath) {
this.log.info("ENTERING getZipFirstEntry, remotePath={} ", remotePath);
/* Setup FTP connection */
final FTPClient ftpClient = this.setupFtpConnection();
try {
ftpClient.changeWorkingDirectory(remotePath.split("/")[0]); /* ftp-folder */
} catch (final IOException e) {
e.printStackTrace();
}
try (final ZipArchiveInputStream zip = new ZipArchiveInputStream(ftpClient.retrieveFileStream(remotePath.split("/")[1]))) { /* input.txt */
this.log.info("EXITING getZipFirstEntry, remotePath={} ", remotePath);
return zip.getNextEntry().getName();
} catch (final IOException e) {
e.printStackTrace();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.