Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA IO : getAbsolutePath()

Tags:

java-io

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.!

like image 814
simoi chigo Avatar asked Apr 24 '26 17:04

simoi chigo


2 Answers

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 : enter image description here

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

like image 116
Butani Vijay Avatar answered Apr 26 '26 07:04

Butani Vijay


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...

like image 25
Jan Hruby Avatar answered Apr 26 '26 06:04

Jan Hruby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!