![]() |
Howto get a relative path to a file
Hi there,
I'm trying to read a configuration file called "user.ini" into my application. When i try to do this from within netbeans everything is fine. After building it however it goes wrong. The application will eventually be called from within the windows scheduler to run daily. therefore i would like to execute it with just a single command like java -classpath "d:\java apps\mahler\dist\jftpmahler.jar" -jar "d:\java apps\mahler\dist\jftpmahler.jar" when i do execute that from the project directory ../dist (where also the .ini file resides) everything is fine. when i do execute the same command from any other location however i get a FileNotFoundException error for the "user.ini" file. now im sure i could make a batch file so i could run it from the application directory. However this is not wanted, therefore i would like to get a relative path to the user.ini file. i have read several posts on different forums on how to get a relative path and use that to make an absolute path to the file but i dont seem to get that working. but that is basically what i want, to get a relative path to the file so, no matter where the application is, it will alway be able to find the ini file. sofar i use this code to open the ini file: ReadIni ini = new ReadIni("user.ini"); public ReadIni(String IniFileName) { inifile = IniFileName; try { p.load(new FileInputStream (inifile)); } catch(Exception e) { //..... } } well im hoping for a solution, but in any case thanks for reading. :thumbsup: |
put it inside the jar file and use
Code:
p.load(this.getClass().getResourceAsStream(inifile)); |
Thanks shyam,
I tried it out and it works fine. this was exactly what i was looking for. |
| All times are GMT +1. The time now is 07:27 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.