bbholzbb
bbholzbb

Reputation: 1932

getting Apppath on Windows XP

With the following Code I want to show my programm's location:

 String myPath =  getClass().getProtectionDomain().getCodeSource().getLocation().getPath();

On Windows 7 it works perfectly, so I get the following result:

C:/Users/Admin/...

But my Problem is Windows XP. I get following URL:

C:/Dokumente%20und%20Einstellungen/Admin/...

How can I replace this %20 in the code?!

This does not work: myPath.replaceAll("%20"," ")

Upvotes: 2

Views: 81

Answers (2)

Vignesh Vino
Vignesh Vino

Reputation: 1238

You can use JFileChooser to find the directory.

String DefaultFolder=new JFileChooser().getFileSystemView().getDefaultDirectory().toString();

Upvotes: 0

BackSlash
BackSlash

Reputation: 22233

myPath.replaceAll("%20"," ");

Does not edit myPath itself, it returns a string that you need to assign to your variable.

myPath = myPath.replaceAll("%20"," ");

Upvotes: 1

Related Questions