Java 如何在httpdocs中列出文件?

Java 如何在httpdocs中列出文件?,java,android,http,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); HttpE

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

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的用户名和密码。

您可以尝试通过从url中删除文件名来启用Web服务器上的目录列表。你已经可以用浏览器测试了。我试过了,但它不起作用。你需要找到文件名,Web服务器安全性阻止它列出文件,因为人们可以用它来攻击服务器。大多数真实的网站都关闭了目录列表。你能让运行它的人输入ftp凭据,或者存储在某个地方然后加密吗?sha2加密的ftp crediantals适合吗?