how to get current directory in java?

后端 未结 4 1651
无人共我
无人共我 2021-01-13 14:34

I am trying to get current directory of my Project from java. I am using the following lines of codes to get the path details.

Type 1:

File directory         


        
4条回答
  •  不要未来只要你来
    2021-01-13 15:11

    you can use this code

    String absolutePath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
            absolutePath = absolutePath.substring(0, absolutePath.lastIndexOf("/"));
    

    this code is working before for me! it will return the full path of folder in windows or linux.

提交回复
热议问题