• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert a java.net.URL to java.io.File

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

i'm looking for a solution, to convert a URL to a File. I need to copy files which are located on a remote server (http://...) to a local folder.

I'm able to copy single files from the remote HTTP-server to my local machine. I received a BufferedReader over the InputStream of the URL.


The rest is only a normal copy like it is used for two local files.

My problem is that I need to copy not only a single file, but a whole folder with all subfolders and files recursively. Normally this is a simple operation with the class java.io.File, but this class does only work for files and folders that are located in the local filesystem.

If 've found with the forum search similar threads about this problem, but no thread gives an sufficient answer on this question. I hope that this thread will give one.

Best regards,
Christian Nicoll
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By default, HTTP does not allow browsing through the remote file system. Therefore, given a URL, it's by default impossible to get all "sub URLs".

Some browsers allow browsing a folder if there is no default document for that folder*, but even then that is an HTML page which you will need to parse.

Is it perhaps possible to use FTP instead of HTTP? Because FTP does allow for listing folder contents.


* If there is no default document, the browser can still give you a "directory listing not allowed" page.
 
Christian Nicoll
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob,

thanks for your fast answer. I will have to look for another solution.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic