How to get list of files/directories of an directory URL?

前端 未结 2 1695
离开以前
离开以前 2020-11-28 11:36

Let say I have a URL: http://java.sun.com/j2se/1.5/pdf I want to get a list of all files/directories under the pdf directory.

I\'m using Ja

2条回答
  •  天命终不由人
    2020-11-28 11:49

    If the URL is for the file: protocol, then you could convert it to a java.io.File, then use those methods to list the directory.

    If the URL is for the http: protocol, then there is no concept of directories of files, and you fundamentally cannot do what you think you want to do. You will have to step back and look at the higher-level requirement you are trying to fulfill.

    Have your server deploy a Servlet to retrieve a list of files from the folder specified by the request it receives. At your client end point, your application sends a request to the server by providing a path (virtual? relative ?) you intend to list. The servlet will return the list of files in the requested path, retrieved from the server's OS. Then, it serializes the file list to the client end point for further processing.

    If you can render the page with HTTP access only then:
    Use the HTML page and parse it giving directory listing to get the list of the files and viz-a-viz using regular expression to render the file names.

提交回复
热议问题