Thursday, September 4, 2014

How to get current working directory in Java - resolved

The current working directory is the root directory of your java project. There are several ways to retrieve the current working directory.

1. System.getProperty("user.dir"))

           public class CurrentDirectoryTest {
                      public static void main(String[] args){
                              System.out.println("Current Directory is: "+System.getProperty("user.dir"));
                      }
           }

2. Paths.get("").toAbsolutePath().toString()
   
          public class CurrentDirectoryTest {
                      public static void main(String[] args){
                              System.out.println("Current Directory is: "+Paths.get("").toAbsolutePath().toString());
                      }
           }

3. (new File("")).getAbsolutePath()

           public class CurrentDirectoryTest {
                      public static void main(String[] args){
                              System.out.println("Current Directory is: "+(new File("")).getAbsolutePath());
                      }
           }

---------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment