Get the path to the application to create a new file

How can I get the application path to the project in a String LogPath variable. LogPath is used later to create the project log file. I use Eclipse for coding.

+4
source share
4 answers

USING

String AbsolutePath = new File(".").getAbsolutePath(); 

Explanation: File(".") Represents the current directory, and getAbsoultePath() returns the absolute path to the current directory.

Hope this helps :-)

+4
source

I would use

 String logPath = new File(".").getAbsolutePath(); 

.. to start.

+4
source

This call: new File(".").getAbsolutePath() provides the current working directory of your application. Hope this answers your question.

+1
source

What language do you use?

Java:

 File directory = new File ("."); System.out.println ("Current directory canonical path: " + directory.getCanonicalPath()); System.out.println ("Current directory absolute path: " + directory.getAbsolutePath()); 
+1
source

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


All Articles