The file class has two seemingly similar methods Touri () and Tourl (), both of which convert files to a link that can be accessed by the network. URIs and URLs have a wider range of applications than URIs.
So why use Touri () instead of Tourl ()? This is easier if you want to convert the file to a URL. Because there is a bug in Tourl ().
When file is converted to a URI, the special words in the link will be such as # or! Encoding, and Tourl () does not.
If you convert "c:documents and settingstest.xsl"
Touri () obtained: File:/c:/documents and settings/test.xsl
Tourl () obtained: File:/c:/documents and settings/test.xsl
That is to say Touri () translates the spaces into, and Tourl () nothing. Sun also mentions this bug (4273532,6179468).
Although there is no problem with translation in the browser, some browsers are automatically translated. However, many programs or components will throw an exception to such a path, and there is a real example of this bug.
So to convert the file to a URL, use File.touri (). Tourl () instead of File.tourl ()
Java URI and URL issues