It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes Incorrect paths in Netbeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Incorrect paths in Netbeans" Watch "Incorrect paths in Netbeans" New topic
Author

Incorrect paths in Netbeans

Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
I'm running netbeans 3.6, basically whenever i attmpt to load or write a file in my project netbeans looks in the netbeans directory instead of the project.

Which means i have to specify the absolute path in the java, which isn't very useful.

Is there a way of specifying the path relative to the netbeans project???

sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68
hi,

Is there a way of specifying the path relative to the netbeans project???


Use getClass().getResource(string) to get files relative to project

example,
getClass().getResource("HomePage.java"); // direct file
getClass().getResource("/images/left_arrow.jpg") // in sub directory

Hope This Helps.

[ March 27, 2005: Message edited by: sasi kala ]
Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
So in context of my program how does it work as if i try either :




or


The first errors and the second returns a null pointer exception..
Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
Ok i can get it to partially work using



but netbeans keeps inserting it's own local path in front when i try to read the file in,

sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68
hi Jamie,

Sorry, i forget to send that one. to read data of any file use
File f = new File(getClass().getResource("Abc.txt").getFile());



getClass().getResource() will return a url of that resource like "file:/c:/tempDir/Abc.txt", if u need file url use
"getFile()" method it will conver the path as "c:\tempDir\Abc.txt".

All The Best
[ March 28, 2005: Message edited by: sasi kala ]
Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
Hi sasi,
Thanks for that, though the problem seems to be that netbeans is still inserting it's own local path onto the front of that:



so it's inserting the c:\program files\netbeans in front of the file address???

 
Don't get me started about those stupid light bulbs.
 
subject: Incorrect paths in Netbeans
 
Similar Threads
Classpaths in Eclipse
Accessing files in NetBeans
Java executable
how to run the jasper report in jar file
How can I get application path from java code?