• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Files path

 
Isaac Durá
Ranch Hand
Posts: 859
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have project structure like



I try to access like this but it doesn´t find the file



But if I try



It works. I want something like



Any idea, please?

Thanks



 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, you can't use packageName.packagerResources.file.data when referring to an external resource or File because the . is not a path separator in any system. The best you can do is packageName/packageResoures/file.data because the forward slash is a recognized path separator. You can also use the ClassLoader.getResource() with that type of path to get a URL to the data (which you may be able to turn into a File) or you could use ClassLoader.getResourceAsStream() to get it directly as an InputStream if what you want to do is read from it. You can even shorten the thing if you are in the packageName.file.class by using getClass().getResourceAsStream("packageResource/file.data").
 
Isaac Durá
Ranch Hand
Posts: 859
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using packageName/packageResoures/file.data

Error the system can´´t find the path

It seems correct to me

Any idea, please?


Thanks
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show the code that uses that line, check spelling, remember that the path is case sensitive (even if the underlying OS is not (for example in Windows pacakageName is the same as PACKagename, but in Java they aren't the same).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic