• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Christian Nicoll
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Pie
Posts: 20753
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hi Rob,

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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic