Why is the function java.io.File.toURL()
deprecated? I need to pass an URL to Toolkit.createImage()
which accepts a URL object. Javadoc recommends me to use File.toURI().toURL()
. However:
C:\Documents and settings\Administrator\...
becomes:
C:\Documents%20and%20settings\Administrator\...
which obviously is an invalid file location. I've found File.toURL() to create URL's without the escaping, however it's deprecated. Although it works I'm scared of using deprecated functions. What's a method that's not deprecated that does the same thing?
EDIT: Right now my code looks like:
spriteImage1 = tkit.createImage(new File("./images/sprite1.png").getCanonicalFile().toURL());
EDIT: I need to create an Image from a folder outside my .jar file. I'll need a relative location ("./images/sprite1.png"). The method createImage(String) throws an exception when I try to give it the relative path.