Get your CodeRanch badge!*
The moose likes Java in General and the fly likes Files path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Files path" Watch "Files path" New topic
Author

Files path

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 321
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

Joined: Jan 28, 2003
Posts: 3969
    
  17

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").


Steve
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 321
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

Joined: Jan 28, 2003
Posts: 3969
    
  17

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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Files path
 
Similar Threads
FileNotFoundException in wired situation
Creating New Ms-Aceess(mdb) file from Java?
FileNotFoundException - Access is denied
How to create a thread?
Faster alternative(s) to java.util.zip??