Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local file protocol for java.net.URL

What's the protocol for local files using URL? I've downloaded a file using Java and I need to know how to access it, not using File, but using URL.

like image 836
Ziddia Avatar asked Dec 06 '11 20:12

Ziddia


People also ask

Can a URL be a file path?

file is a registered URI scheme (for "Host-specific file names"). So yes, file URIs are URLs.

How do I download a file in Java?

To download a file from a given URL using the Apache Commons IO we will require the FileUtils class of the package. There is only a single line of code required to download a file, which looks like: FileUtils. copyURLToFile( new URL("http://example.com/my-file-path.txt"), new File("/Users/username/Documents/file_name.


2 Answers

Unix

file://localhost/<path>
file:///<path>

Windows

file://localhost/<drive>|/<path>
file:///<drive>|/<path>
file://localhost/<drive>:/<path>
file:///<drive>:/<path>

For more information see the related Wikipedia article.

like image 57
Kohányi Róbert Avatar answered Oct 12 '22 04:10

Kohányi Róbert


You may use file:/// and file path. For e.g. file:///c:/temp.txt

like image 23
jatanp Avatar answered Oct 12 '22 03:10

jatanp