How to get the current working directory in Java?

I want to access my current working directory using Java. My code: String currentPath = new java.io.File(“.”).getCanonicalPath(); System.out.println(“Current dir:” + currentPath); String currentDir = System.getProperty(“user.dir”); System.out.println(“Current dir using System:” + currentDir); Output: Current dir: C:\WINDOWS\system32 Current dir using System: C:\WINDOWS\system32 My output is not correct because the C drive is not my current directory. How … Read more

Getting java.net.SocketTimeoutException: Connection timed out in android

I’ve searched all over the web and after reading lot of docs regarding connection timeout exception, the thing I understood is that, preventing SocketTimeoutException is beyond our limit. One way to effectively handle it is to define a connection timeout and later handle it by using a try-catch block. Hope this will help anyone in future who are facing … Read more

How to get the current working directory in Java?

Code : public class JavaApplication { public static void main(String[] args) { System.out.println(“Working Directory = ” + System.getProperty(“user.dir”)); } } This will print the absolute path of the current directory from where your application was initialized. Explanation: From the documentation: java.io package resolve relative pathnames using current user directory. The current directory is represented as system property, … Read more