How to get the current working directory in Java?

前端 未结 22 3154
时光说笑
时光说笑 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条回答
  •  旧时难觅i
    2020-11-21 08:15

    Mention that it is checked only in Windows but i think it works perfect on other Operating Systems [Linux,MacOs,Solaris] :).


    I had 2 .jar files in the same directory . I wanted from the one .jar file to start the other .jar file which is in the same directory.

    The problem is that when you start it from the cmd the current directory is system32.


    Warnings!

    • The below seems to work pretty well in all the test i have done even with folder name ;][[;'57f2g34g87-8+9-09!2#@!$%^^&() or ()%&$%^@# it works well.
    • I am using the ProcessBuilder with the below as following:

提交回复
热议问题