Logo

Programming-Idioms

  • Lisp
  • Java

Idiom #106 Get program working directory

Assign to string dir the path of the working directory.
(This is not necessarily the folder containing the executable itself)

import java.io.File;
String dir = new File("").getAbsolutePath();

"... If this abstract pathname is the empty abstract pathname then the pathname string of the current user directory, which is named by the system property user.dir, is returned."
String path = this.getClass().getClassLoader().getResource("").getPath();
String dir = System.getProperty("user.dir");

The "user.dir" property will return the user working directory.
with Ada.Directories; use Ada.Directories;
Dir : String := Current_Directory;

New implementation...
< >
programming-idioms.org