0

I am currently trying to get the path of a current java class called "WordBase". I am using the following code.

    final File f = new        

    File(WordBase.class.getProtectionDomain().getCodeSource().getLocation().getPath());
    System.out.println(f);

This gives me the following output:

    C:\Users\Rasmus%20J\wordbase\out\production\wordbase

Which is incorrect. Correct would be:

    C:\Users\Rasmus J\wordbase\out\production\wordbase

Is there any way to clean things up and get a correct output? I want the code to be able to run on all different kind of computers from different paths. Perhaps there is an even easier way than using class.getProtectionDomain()...?

Thanks in advance.

RasmusJ
  • 396
  • 1
  • 2
  • 10
  • This technique does not work under all circumstances - see [here](http://stackoverflow.com/a/19494116/823393) for a more resilient solution. – OldCurmudgeon Mar 28 '14 at 16:33

1 Answers1

1

What you get is encoded URL.

What you need is to decode it

URLDecoder.decode(url, "UTF-8");
Nazarii Bardiuk
  • 4,272
  • 1
  • 19
  • 22