最开始我是用能够这种方式来获取当前 jar 包的文件的:
但是如果路径中包含中文,就会变成带“%xx%xx”格式的字符串。所以应该这样写才对:
private static String LOCATION = [MainClass].class.getProtectionDomain()
.getCodeSource().getLocation().getFile();
.getCodeSource().getLocation().getFile();
但是如果路径中包含中文,就会变成带“%xx%xx”格式的字符串。所以应该这样写才对:
private static String LOCATION;
static {
try {
LOCATION = URLDecoder.decode([MainClass].class.getProtectionDomain()
.getCodeSource().getLocation().getFile(), “UTF-8″);
} catch (UnsupportedEncodingException e) {
LOCATION = “”;
}
}
static {
try {
LOCATION = URLDecoder.decode([MainClass].class.getProtectionDomain()
.getCodeSource().getLocation().getFile(), “UTF-8″);
} catch (UnsupportedEncodingException e) {
LOCATION = “”;
}
}