gpt4 book ai didi

java - 如何在java中下载整个文件夹?

转载 作者:行者123 更新时间:2023-11-29 03:43:34 26 4
gpt4 key购买 nike

我想从服务器下载整个文件夹/目录。该文件夹包含文件。我尝试使用 zip 功能,但为此我需要提供文件路径而不是文件夹路径。

喜欢-

BufferedInputStream in = new BufferedInputStream(new FileInputStream("d:\\StoreFiles\\Temp\\profile.txt"));

我想要类似 ("d:\StoreFiles") 的东西,它将下载 Storefiles 文件夹中的所有文件夹和文件夹内的文件。

我该如何实现?

最佳答案

这个怎么样?它递归地进入目录并下载:

  public static void main(String[] args) {
directoryDownloader(new File("/Users/eugene/Desktop"));
}

private static void directoryDownloader(File input){
if(input.isDirectory()){
for(File file : input.listFiles()){
directoryDownloader(file);
}
} else {
downloadFile(input);
}
}

private static void downloadFile(File someFile){
System.out.println("Downloading file : " + someFile.getPath());
}

附言以您想要的方式实现 downloadFile。

关于java - 如何在java中下载整个文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12067301/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com