How to find out current working directory in Java

0 votes
I want to access data present on my current working directory, how to do it?
Apr 25, 2018 in Java by Daisy
• 8,110 points
158 views

2 answers to this question.

0 votes

We can easily find out the current working directory in Java.

public class Demo {

public static void main(String[] args) {

    System.out.println("Current Working Directory = " +

              System.getProperty("user.dir"));

}
}
answered Apr 25, 2018 by Parth
• 4,630 points
0 votes
You can also use java.nio.file.Path and java.nio.file.Paths.
Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
System.out.println("Current relative path is: " + s);
answered Jul 30, 2018 by Sushmita
• 6,890 points

Related Questions In Java

0 votes
1 answer

How to get the current working directory in Java?

Hello, Using java.nio.file.Path and java.nio.file.Paths, you can do the following to ...READ MORE

answered May 28, 2020 in Java by Niroj
• 82,580 points
656 views
0 votes
1 answer

In Java, how to find out the min/max values from array of primitive data types?

import java.util.Arrays; import java.util.Collections; import org.apache.commons.lang.ArrayUtils; public class MinMaxValue { ...READ MORE

answered Jun 12, 2018 in Java by Daisy
• 8,110 points
339 views
0 votes
2 answers

How can I Copy files from one directory to another in Java

Java 8 Path sourcepath = Paths.get("C:\\data\\temp\\mydir"); ...READ MORE

answered Aug 10, 2018 in Java by samarth295
• 2,200 points
1,902 views
0 votes
1 answer

How to find the nth prime number in Java?

Here is the code to find nth ...READ MORE

answered Mar 4, 2019 in Java by Priyaj
• 58,100 points
21,790 views
0 votes
1 answer

How to create a temporary directory/folder in java?

If you are using JDK 7 use ...READ MORE

answered Aug 28, 2018 in Java by Frankie
• 9,810 points
5,142 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 6, 2018 by Omkar 38,534 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,520 points
5,069 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,520 points
11,450 views
0 votes
2 answers

How to find out a single character appears in String or not in Java?

You can use string.indexOf('s'). If the 's' is present in string, ...READ MORE

answered Aug 7, 2018 in Java by Sushmita
• 6,890 points
1,180 views
0 votes
5 answers

How to compare Strings in Java?

String fooString1 = new String("foo"); String fooString2 = ...READ MORE

answered Jul 12, 2018 in Java by Daisy
• 8,110 points
382 views