How to get current working directory in java?

DeeKay April 6, 2012 at 2:39 am · java.io

You can get current working directory using System.getProperty("user.dir") function. Here current working directory means the root folder of your current Java project.

Below java code shows how to get current working directory of user –

/****************************************************************************************
 * Created on 04-2012 Copyright(c) http://kodehelp.com All Rights Reserved.
 ****************************************************************************************/
package com.kodehelp.javaio;

/**
 * Created by http://kodehelp.com
 * Date: 4/5/12
 */
public class GetCurrentWorkingDirectory {
    public static void main(String args[]){
        String workingDirectory = System.getProperty("user.dir");
        System.out.println("Your Current Working Directory is ::"+workingDirectory);
    }
}

 

References: