假设您正在使用任何类型的文件 IO,
public class example{
public Example(){
File file = new File(getClass().getProtectionDomain().getCodeSource().getLocation());
//file IO process ....
}
}
通过使用 getClass().getProtectionDomain().getCodeSource().getLocation()
,您将获得“example.jar”的完整路径。
那么,如何在没有“example.jar”的情况下获取该文件位置?
(所以实际上是 jar 所在的文件夹,而不是指向 jar 本身的链接)
最佳答案
关于java - 在 jar 之前提取文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17902344/