dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Jun 3, 2021

Finding the Current Directory in Java

Java has many methods developers can employ to figure out the current working directory. We will be examining one of those today, as we use the Java method java.lang.System.getProperty() and the parameter user.dir.

Here is a brief Java application that shows how to use java.lang.System.getProperty() to find the current working directory:

*/

public class FindCurrentDir 
{ 
	public static void main(String[] args) 
	{
		FindCurrentDir findCurrentDir = new FindCurrentDir();
		findCurrentDir.proceed();
	}

	private void proceed()
	{
		String currentDir = System.getProperty("user.dir");
		System.out.println("Current working directory is " + currentDir);
	} 
} 

/*

You should get the following output when you run this Java code sample:

[root@mypc]# java FindCurrentDir
Current working directory is /opt/java-apps/dir-functions
MS Sridhar
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date