How to locate the Path of the current project directory in Java (IDE)?

前端 未结 9 1409
梦如初夏
梦如初夏 2020-11-28 21:46

I am trying to locate the path of the current running/debugged project programmatically in Java, I looked in Google and what I found was System.getProperty(\"user.id\"

9条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 22:27

    File currDir = new File(".");
    String path = currDir.getAbsolutePath();
    System.out.println(path);
    

    This will print . at the end. To remove, simply truncate the string by one char e.g.:

    File currDir = new File(".");
    String path = currDir.getAbsolutePath();
    path = path.substring(0, path.length()-1);
    System.out.println(path);
    

提交回复
热议问题