File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get File list from URL

 
robin singal
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

How can i get the list of file names from a url location .
I want something like this:

File f = new File(<url> ;
File[] fileNames = f.listFiles();

As it's not possible to access url with the above..

Thanks
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An URL is not a directory of a file system, so you can't use file I/O to access it. What exactly is the scenario you're trying to address?
 
robin singal
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

My question is as one can access the file names in a local directory using the above code. How can i do the same for a url location?? And yes i know it's not possible to access url using the above code. Is there any way to do the same for a url location. using java.net.* or something else. I did tried to find the way but didn't find one!!

Thanks & regards
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no way to get a directory listing unless code on the remote machine wants to give you one. Some web servers are configured to give directory listings of certain directories; that would just be an HTML page containing the list of files, and you'd access it using the HttpURLConnection class.

Another possibility is a ftp:// URL. An ftp server will generally be happy to give you directory listings, if you issue the appropriate command. For these, your best best is a third-party FTP library. There's one in Apache's Jakarta Commons, I believe.
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

If the URL is for some other protocol, you'd better tell us what it is.
 
robin singal
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for delayed response..
I can render page with http access only and I did solved the problem.
I used the html page giving directory listing to get the list of the files and viz-a-viz using regular expression to render the file names.

Thanks for the replies.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:

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 can when the server is implementing WebDav, can't you?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic