In this quick coding tip we will see how to get user’s current working directory or Java execution path using java.lang.System class.
Java code for getting user’s current working directory or Java execution pathOUTPUT of the above code
Quick explanation of the above code
- The above code uses
java.lang.Systemclass which as its name suggests is a system-level class used for fetching environment specific details among other system-wide utilities that it also provides.
- System’s static method
getProperty()is used to retrieve environment specific values with the syntax –
static String getProperty(String key)
- For getting the user’s current working directory we need to pass the designated key for the same which is ‘
- In return I got the local Windows directory path for my system which has been printed above as output.