Can a Java program know its current directory?

Is it possible for a Java application to know its own current directory. I mean the result of pwd .

For example, when doing

 ~/Documents/workspace/Project/bin $ java com/foo/bar/baz/Runner files/text1.txt program should know ~/Documents/workspace/Project/bin ~/Documents/workspace/Project $ java com/foo/bar/baz/Runner files/text1.txt program should know ~/Documents/workspace/Project 
+6
source share
3 answers

Perhaps this helps:

 File cwd = new File("."); 
+12
source
+7
source

This is called the working directory. You can get it with the following instruction:

 System.getProperty("user.dir"); 
+4
source

Source: https://habr.com/ru/post/907780/


All Articles