共計 420 個字符,預計需要花費 2 分鐘才能閱讀完成。
在 Java 中,你可以使用 `System.getProperty(“user.dir”)` 方法來獲取當前工作目錄的路徑。
下面是一個示例代碼片段演示如何獲取當前目錄路徑:
public class CurrentDirectoryExample { public static void main(String[] args) { String currentDir = System.getProperty("user.dir");
System.out.println("當前目錄路徑:" + currentDir);
}
}
在上述代碼中,`System.getProperty(“user.dir”)` 方法返回一個字符串,其中包含當前工作目錄的路徑。然后,我們使用 `System.out.println()` 方法將該路徑打印到控制臺。
運行上述代碼將輸出當前目錄的路徑。
丸趣 TV 網 – 提供最優質的資源集合!
正文完