Listing files of a folder present in the http server

后端 未结 3 934
清酒与你
清酒与你 2021-01-22 19:11

I have a question related to Http. In android how to list the files of a folder which is in Http server.

I am able to Download file from server. But I want to check fil

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-22 19:52

    You will need a server side script to list the files such as this one in PHP

    Place the file in the directory with all the files you want to see, called listfiles.php

    ';
                $thelist = $thelist.$file."\r\n";
              }
           }
      closedir($handle);
      }
     echo $thelist;
    ?>
    

    Then in your android java app, you will download the file, and then build an array of the filenames for your processing.

    String serverFile = "path on your server/listfiles.php";
    String listOfFiles = DownloadText(serverFile);
    String[] linesOfFiles = listOfFiles.split("
    ");

    Then you have a string array of all of the files on the server. I have not included the code for the DownloadText function, but that is very standard and you can find it easily. It will download any text file over HTTP.

    HTH

提交回复
热议问题