Rob*_*boy 68
不是一个完美的解决方案,但这将返回类代码库的位置:
getClass().getProtectionDomain().getCodeSource().getLocation()
Run Code Online (Sandbox Code Playgroud)
Boz*_*zho 14
正如评论中所指出的,这不是问题的直接答案,但可能实际上是许多人正在寻找的(执行代码的当前目录):
new File(".").getAbsolutePath()
Run Code Online (Sandbox Code Playgroud)
小智 7
这是我从任何地方获取执行路径的方法
private static String GetExecutionPath(){
String absolutePath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
absolutePath = absolutePath.substring(0, absolutePath.lastIndexOf("/"));
absolutePath = absolutePath.replaceAll("%20"," "); // Surely need to do this here
return absolutePath;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
57685 次 |
| 最近记录: |