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,140 points
1,027 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,640 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 31, 2018 by Sushmita
• 6,920 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,840 points
3,999 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,140 points
1,660 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,220 points
4,444 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,020 points
39,390 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,830 points
6,430 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 7, 2018 by Omkar 81,373 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,500 points
8,402 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,500 points
17,492 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,920 points
5,758 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,140 points
2,574 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP