J
James
eg.
c:\myapp\test.class
c:\myapp\icon\icon1.gif
c:\myapp\setting.cfg
when I compile and run test.class
in coding, I write
something.setImageIcon(getClass().getResource("/icon1.gif"));
after process something, the program will save the file setting in
setting.cfg
something.savefile(new
File(getClass().getResource("/setting.cfg").toString()));
all of this run ok, the image got load up, then when save setting, it got
write back into setting.cfg file.
Later I group all of this in 1 jar file.
then when I try the program, it cannot run anymore. something related to
nullpointerexception.
I try to get out the path and I found out that when running in normal
class(without jar), that code can get correct path and the file.
but when run in jar(with main class) that code can't get correct path.
It got something at between the parent path and class path.
at center it come out something like jar file(it act like 1 level path)
so I want to ask you all, normally how do you all get the running path
correctly so that can load the image and save file back to running class's
path
c:\myapp\test.class
c:\myapp\icon\icon1.gif
c:\myapp\setting.cfg
when I compile and run test.class
in coding, I write
something.setImageIcon(getClass().getResource("/icon1.gif"));
after process something, the program will save the file setting in
setting.cfg
something.savefile(new
File(getClass().getResource("/setting.cfg").toString()));
all of this run ok, the image got load up, then when save setting, it got
write back into setting.cfg file.
Later I group all of this in 1 jar file.
then when I try the program, it cannot run anymore. something related to
nullpointerexception.
I try to get out the path and I found out that when running in normal
class(without jar), that code can get correct path and the file.
but when run in jar(with main class) that code can't get correct path.
It got something at between the parent path and class path.
at center it come out something like jar file(it act like 1 level path)
so I want to ask you all, normally how do you all get the running path
correctly so that can load the image and save file back to running class's
path