when i create a new dynamic web project and execute the code below :
File file = new File("");
String path = file.getAbsolutePath();
System.out.println(path);
I get this result:
C:\Users\Toshiba\workspace\Projet .
which is good!!!. But when i import another project and execute the same code ,i get this :
D:\Eclipse .
(the path of eclipse's application ).
and that!! i can't explain or fix.
Any help.!
Because it take default location of your project ( working directory )when you pass nothing in new File("").
I have uploaded image so you can understand easily :

Suppose your workspace path is : c:/test/myworkspace
you configure working directory as above ( in image )
and then run you get some thing like this : c:/test/myworkspace/TestJquery
Have you checked the documentation of the method?
If this abstract pathname is already absolute, then the pathname string is simply returned as if by the getPath() method. If this abstract pathname is the empty abstract pathname then the pathname string of the current user directory, which is named by the system property user.dir, is returned. Otherwise this pathname is resolved in a system-dependent way. On UNIX systems, a relative pathname is made absolute by resolving it against the current user directory. On Microsoft Windows systems, a relative pathname is made absolute by resolving it against the current directory of the drive named by the pathname, if any; if not, it is resolved against the current user directory.
this is probably all the information you need...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With