Alex Rivera | Logout

File.toURL() deprecated?

Asked 2009-04-22T14:15:02.780
19

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.

Edit
Report

1 Answer

1

You could consider using ImageIO as an alternative.

answered 2009-04-22T14:26:08.573

Your Answer