java - getAbsolutePath ignoring certain folders -


my problem getabsolutepath ignoring folders around file i'm trying find. i'm trying filepath of file using name. here's code i'm using:

import java.awt.desktop; import java.io.file; import java.io.ioexception;  public class openfile {     public static void main(string[] args) throws ioexception{         file file = new file("point.java");         string path = file.getcanonicalpath();          try {             desktop.getdesktop().open(new file(path));         } catch(ioexception e) {             system.out.println("not work");         }     } } 

i'm getting error:

exception in thread "main" java.lang.illegalargumentexception: file: /users/default/desktop/eclipse/treething/point.java doesn't exist. @ java.awt.desktop.checkfilevalidation(desktop.java:210) @ java.awt.desktop.open(desktop.java:270) @ forkbomb.main(forkbomb.java:11) 

the real filepath /users/default/desktop/eclipse/treething/src/point.java, because directory src being ignored program won't run. how can solve it?

it appears running code /users/default/desktop/eclipse/treething directory. sets 'current working directory' application.

so when instantiate file object without path, code assumes in current working directory.

it not perform search you.

if want refer existing point.java, use either:

file file = new file("src/point.java"); 

... or:

file file = new file("/users/default/desktop/eclipse/treething/src/point.java"); 

Comments