How to get the current working directory in Java?

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

    this is current directory name

    String path="/home/prasad/Desktop/folderName";
    File folder = new File(path);
    String folderName=folder.getAbsoluteFile().getName();
    

    this is current directory path

    String path=folder.getPath();
    

提交回复
热议问题