Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the real path of Java application at runtime?

Tags:

java

filepath

I am creating a Java application where I am using log4j. I have given the absolute path of configuration log4j file and also an absolute path of generated log file(where this log file are generated). I can get the absolute path of a Java web application at run time via:

String prefix =  getServletContext().getRealPath("/"); 

but in the context of a normal Java application, what can we use?

like image 210
Sameek Mishra Avatar asked Oct 27 '10 12:10

Sameek Mishra


1 Answers

Try;

String path = new File(".").getCanonicalPath(); 
like image 174
Qwerky Avatar answered Oct 14 '22 07:10

Qwerky