• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Incorrect paths in Netbeans

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???

 
Looky! I'm being abducted by space aliens! Me and this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic