String current = new java.io.File( "." ).getCanonicalPath();
System.out.println("Current dir:"+current);
String currentDir = System.getProperty("user.dir");
System.out.println("Current dir using System:" +currentDir);
It's my code, but the result is
Current dir: C:\WINDOWS\system32
Current dir using System: C:\WINDOWS\system32
It comes out like this But this isn't it because drive C is not the current folder... Help me
java working-directory
public class JavaApplication1 {
public static void main(String[] args) {
System.out.println("Working Directory = " +
System.getProperty("user.dir"));
}
}
This will print out the full address where the program is installed.
If it doesn't work
Write java.nio.file.Path
and java.nio.file.Paths
to view 's current working directory.
Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
System.out.println("Current relative path is: " + s);
When I do this, I get output like Current relative path is: /Users/george/NetBeans Projects/Tutorials
.
© 2024 OneMinuteCode. All rights reserved.