krzakov
krzakov

Reputation: 4111

How to get eclipse root path in code?

Can I from code get the absolute path of Java a project in Eclipse ex C:\workspace\proj1?

Thing is that code will be runned on different machines, so path will be different, depending on the machine.

Is there a way to achieve that?

Upvotes: 1

Views: 798

Answers (1)

An SO User
An SO User

Reputation: 24998

You can use System.getProperty("user.dir") and find the directory from which the program is run. If you look at the docs, you will get the description below:

user.dir    User's current working directory  

SSCCE:

public class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        System.out.println(System.getProperty("user.dir"));
    }
}

Upvotes: 2

Related Questions