tags:

views:

57

answers:

2

Today I saw in a Java application several different approaches to load a file.

  • file:/
  • file://
  • file:///

What is the difference of these three URL beginnings and what is the preferred way of using them?

Thanks a lot Stefan

+2  A: 

file:/ is invalid, and shouldn't work file:/// is a shorthand for: file://localhost/ file:// is the recommended method

Ayende Rahien
+5  A: 
  • file:/ is invalid as far as I know

  • file:// is the prefix for the file protocol

  • file:/// is the prefix for the file protocol, plus a leading / pointing to the root directory of the current drive (On Windows) or the overall root directory (On Linux / Unix).

Pekka
+1 On windows remote drives, the `file://` protocol prefix leads to even four slashes: `file:////other/mydir/myfile.txt` for a file `\\other\mydir\myfile.txt` (see http://mindprod.com/jgloss/uri.html).
Chris Lercher
@chris_li ahahahaha, hadn't thought of that scenario! That looks just *crazy*. Great addition.
Pekka