如何在httpdocs中列出文件?

时间:2014-09-12 15:30:17

标签: java android http

我正在尝试从网站上获取一些文件。我想这样做,但我不知道文件名。

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://www.examplewebsite.com/Directory1/Directory2/Text.txt");
HttpResponse response = null;
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
    long len = entity.getContentLength();
    inputStream = entity.getContent();
    // write the file to whether you want it.
}
String filePath = "Text.txt";
FileOutputStream fos = new FileOutputStream(new File(filePath));
int inByte;
while((inByte = inputStream.read()) != -1) fos.write(inByte);
inputStream.close();
fos.close();

怎么可以自动这种方式?顺便说一句,我不想​​进入ftp服务器并列出项目,并在这里添加www.exampleserver.com/Directory1/Directory2/。也许如果我找不到另一种方式,我会用它但我不想写ftp的安全用户名和密码。

0 个答案:

没有答案