Steven
Steven

Reputation: 4022

URL load error during adding

i have a string say Path ="C:\AAA\bin" which is a path to a project's bin folder. I used new URL(Path) during invocation of addURL method of URLClassLoader class.

ex- addURL(sysLoader,new URL(Path)) ;

its giving unknown protocol:c exception

whats the problem?Help

Upvotes: 0

Views: 83

Answers (3)

b.roth
b.roth

Reputation: 9532

Replace new URL(Path) with new File(Path).toURL() and it will work.

Also, don't forget to escape the \ in the file path:

"C:\\AAA\\bin"

Upvotes: 0

Riduidel
Riduidel

Reputation: 22292

You first have to tranform your String path into an URL. The simplest way is to create a File from your String path, then call its toURI method.

in other words :

addURL(sysLoader, new File(Path).toURI().toURL());

Upvotes: 1

navr
navr

Reputation: 72

you have to use something like this

Path="file://C://AAA/bin". 

Here 'file' refers to the protocol.

Upvotes: 1

Related Questions