deprecated File toURL() method in Java 6

Posted on October 8, 2007. Filed under: Java programming | Tags: , , , , , , , , |

after upgrading to Java 6, I just found out that toURL() method is deprecated in Java 6.
after doing some googling, I reached to this page: http://www.jguru.com/faq/view.jsp?EID=1280051

The author (in the link above) said:

The toURL() method of File does not properly escape characters that aren’t valid in a URL. You can write better code today without waiting for Java 6 by calling the toURL() method after calling toURI() on a File object.

and provided these code samples for us:


    URL url1 = file.toURL();         // bad
    URL url2 = file.toURI().toURL(); //good

hmmm … okay, I got it.

Make a Comment

Make A Comment: ( None so far )

blockquote and a tags work here.

Liked it here?
Why not try sites on the blogroll...