aspose file tools*
The moose likes I/O and Streams and the fly likes Convert a java.net.URL to java.io.File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Convert a java.net.URL to java.io.File" Watch "Convert a java.net.URL to java.io.File" New topic
Author

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

Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
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

SCJP 5, SCJD 5, SCWCD 5, SCBCD 5, SCJDWS 5
My SCBCD-Notes - My Hello World Webservice
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
Hi Rob,

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

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