JAVA:从网络服务器下载文件夹的全部内容

时间:2013-04-10 13:00:57

标签: java download

我正在尝试从Apache Web服务器下载文件夹中的所有文件。到目前为止,我只使用以下代码设法下载单个文件:

import java.net.*;
import java.io.*;

public class DownloadFile{

public static void main(String args[]) throws IOException{

    BufferedInputStream in = new BufferedInputStream(new 
            URL("/WEBSERVER URL/test.txt").openStream());

    FileOutputStream fos = new FileOutputStream("E://test.txt");
    BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
    byte data[] = new byte[1024];

    while(in.read(data,0,1024)>=0){

    bout.write(data);
    }

    bout.close();
    in.close();
    }
}

到目前为止,我只能从我的网络服务器目录下载特定文件,方法是从我的网络服务器和FileOutputStream(“E://test.txt”);中声明文件的全名。有没有办法实现,所以程序可以遍历所有文件,并使用不同的结束标记下载它们,例如.txt和.jpg?

0 个答案:

没有答案