java - FileNotFound exception, when files are in /Applications/Foobar.app on a Mac -


summary - code:

file f = new file("dbfile.dat"); f.getabsolutepath(); 

returns:

/applications/dbfile.dat 

the problem application's resources (3d party jars instance) located in "applications/foobar.app/...".

how path install folder without hardcoding anything?

details:

i'm using 3d party library need provide filename:

ls = new lookupservice("dbfile.dat"); 

when distributed, file placed in root of install folder, next executable files - works great on windows.

however, on mac fnf exception because library isn't searching in correct location:

java.io.filenotfoundexception: dbfile.dat (the system cannot find file specified)     @ java.io.randomaccessfile.open(native method)     @ java.io.randomaccessfile.<init>(unknown source) ... 

try this:

url myclass = myclass.class.getresource("myclass.class"); system.out.println(myclass.getpath()); 

this print out this:

file:/home/mike/test.jar!/myclass.class 

you can parse out need that.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -