How to find a current working directory in java.

The getproperty() method defined in the Java system class is used to retrieve the value of the property named in the parameter list. This attribute of the method is specified by the key accepted by the parameter. If the property does not exist, this version of getProperty returns null.

Syntax :

public static String getProperty(String key)

Parameter :

  • key: key whose system property we want

Returns :

  • System property as specified the key
  • Null: if there is no property present with that key.

Example:

// Java Program to Find
// current working directory
import java.io.*;

public class GFG {
	
	public static void main(String[] args)
	{

		// Getting the path of system property
		String path = System.getProperty("user.dir");

		// Printing the path of the working Directory
		System.out.println("Working Directory = " + path);
	}
}

 

Submit Your Programming Assignment Details