Java 获取当前程序所在的路径
要获取 Java 程序所在的路径,可以使用以下代码示例:
public class CurrentPathExample {
public static void main(String[] args) {
String currentPath = System.getProperty("user.dir");
System.out.println("Current Path: " + currentPath);
}
}
在这段代码中,System.getProperty("user.dir")
方法用于获取当前用户的工作目录,即 Java 程序所在的路径。您可以将这段代码添加到您的 Java 程序中,以获取程序所在的路径。
还没有评论,来说两句吧...