schmimona
schmimona

Reputation: 869

Get current directory from the command prompt when calling a Java application

I have a Java application which I call from the command prompt like this:

C:\Mydir> C:\dir2\my.exe

When I call this application I would like to retrieve at the same time the path "C:\MyDir", i.e. the active directory from where my exe is called in the prompt and not "C:\dir2\" where the exe is found.

How could I do that in Java?

Upvotes: 2

Views: 2875

Answers (2)

Sinisha Mihajlovski
Sinisha Mihajlovski

Reputation: 1831

File f = new File("");
System.out.println(f.getAbsolutePath());

Upvotes: 1

Chris Aldrich
Chris Aldrich

Reputation: 1922

I believe you would use

String currentLocation = System.getProperty("user.dir");

Upvotes: 2

Related Questions