Get Present Working Directory in Java Code

Most of projects we don't use absolute path instead we use relative path thats best practice. in this discussion we will see how to get string name of current working folder so after that we can get relative path corresponding to that base location . so simple just few lines :)
   public static String getCurrentDirectory(){
        String cwd = null;
        try{
            cwd = new java.io.File( "." ).getCanonicalPath();

        } catch (java.io.IOException e)
        {
            log.error("Error in getting present working Directory");
        }
        return cwd;
    }

No comments:

Post a Comment

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...