How to get the current working directory in Java?

前端 未结 22 3123
时光说笑
时光说笑 2020-11-21 07:16

I want to access my current working directory using java.

My code :

 String current = new java.io.File( \".\" ).getCanonicalPath();
        System.ou         


        
22条回答
  •  终归单人心
    2020-11-21 08:15

    generally, as a File object:

    File getCwd() {
      return new File("").getAbsoluteFile();
    }
    

    you may want to have full qualified string like "D:/a/b/c" doing:

    getCwd().getAbsolutePath()
    

提交回复
热议问题