java如何将URL对象转换为字符串
我想将URL转换为字符串。我在网上搜索过,没有找到任何有用的东西。显然有一个toString(URL)方法,但我无法让它工作
public String getLocationJar(){
URL fileLocation = getClass().getProtectionDomain().getCodeSource().getLocation();
return toString(fileLocation);
}
你可以在下面搜索框中键入要查询的问题!
我想将URL转换为字符串。我在网上搜索过,没有找到任何有用的东西。显然有一个toString(URL)方法,但我无法让它工作
public String getLocationJar(){
URL fileLocation = getClass().getProtectionDomain().getCodeSource().getLocation();
return toString(fileLocation);
}
# 1 楼答案
如果我没听错,你只需要打电话给
fileLocation.toString()
或者fileLocation.getPath()
。以下代码:输出所需路径:
所以,只需将代码更改为
return fileLocation.toString()