public String getClassPath(){
String path="";
try {
path=new File(getClass().getClassLoader().getResource("").toURI()).getPath();
}catch (URISyntaxException ex) {}
return path;
}
取程序运行时的目录路径。即程序在那里双击或BAT文件所在的路径
System.getProperties("user.dir");
本文介绍了一种在Java中获取程序运行时所在目录路径的方法。通过使用getClassLoader().getResource()来定位程序当前运行的位置,并利用File对象获取其路径。此外还提供了一个备选方案,即通过System.getProperties(user.dir)来获取工作目录。

被折叠的 条评论
为什么被折叠?



