How to get the current working directory in Java?

前端 未结 22 3089
时光说笑
时光说笑 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:09

    What makes you think that c:\windows\system32 is not your current directory? The user.dir property is explicitly to be "User's current working directory".

    To put it another way, unless you start Java from the command line, c:\windows\system32 probably is your CWD. That is, if you are double-clicking to start your program, the CWD is unlikely to be the directory that you are double clicking from.

    Edit: It appears that this is only true for old windows and/or Java versions.

提交回复
热议问题