2013-04-20 45 views
2

用下面的代码我想表明我PROGRAMM的位置:在Windows越来越APPPATH XP

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

在Windows 7上它完美的作品,所以我得到以下结果:

C:/Users/Admin/... 

但我问题是Windows XP。我收到以下URL:

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

我该如何在代码中替换这个%20 ?!

这不起作用:myPath.replaceAll("%20"," ")

+0

*“我想显示我的程序的位置:”*为什么?这是为了支持哪些应用程序功能? – 2013-04-20 12:46:16

回答

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

不编辑myPath本身,它返回你需要分配给您的变量的字符串。

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

您可以使用JFileChooser来查找目录。

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