Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Incorrect paths in Netbeans

 
Jamie Wool
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic