• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Get File list from URL

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Our first order of business must be this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic