copy file from jar (java webstart)
Hello All!
i ve just run out of ideas.
i am starting my application via java webstart it is a single jar file, nothing
special, clever, or any way out of ordinary. that works (wow!). what i need to do
is: copy a file, which is in this jar file, somewhere.
i managed to do it by calling the getReource method from classloader,
then parsing the output, looking form path to jar file and unpacking from
that file. that works as well (now that is a supprise!) but (another supprise)
there are some pseudo "operating systems" where it does not work.
my question is: is there a simple, elegant and portable (it is after all
write once run allmost every where) method for copying a file from jar archive
in this situation? my guess was that it should work the same way as
does:
new ImageIcon(getResource("images/hullo.gif"));
for File:
new FileInputStream(new File(getResource("myfiletocopy").toURI()));
unfortunatly (it is a post of supprised, as you notice) it does not.
please help, i am half step from throwing my machine from some
high point ..
thanx
peter
[1189 byte] By [
chujaa] at [2007-10-3 0:50:49]

> please help, i am half step from throwing my machine> from some> igh point ..Let's not do anything rash.I found your post a bit hard to follow. Could you please post the formatted code with exactly what you are doing?
Hey there.
> there are some pseudo "operating systems" where it does not work.
Please be more specific about what "it" is that wont work.
If you can run your program then we know the OS is able to get files from the jar. So is your difficulty retrieving the file from the jar yourself or is your question "how do i write this file to the computer"?
Does this help at all: http://forum.java.sun.com/thread.jspa?threadID=633051&messageID=3665680
hej, no problem, i can throw it out any time!
yeah, well it is a bit hard to follow, the author does not follow it at all:)
the problem is simple:
copy the file with given name from jar file to the tempdir.
aplication is started with java webstart, single jar.
in this jar there is a file, lets say "resource/yeah.dat"
i need to copy it to /tmp/dir. i created the temp dir allright,
cant copy the file, cant create FileInputStream for file, cant copy it.
i would prefer not to paste the code in here, it is a bit long and
right now i state of compelte disorder..
thanx for quick reply..
and i hope you do not understand polish, i put a very bad
screen name and i cant change it..
peter
chujaa at 2007-7-14 17:45:54 >

> hej, no problem, i can throw it out any time!Sorry. Must. Stop. Laughing. That was pretty funny. Why don't you use getResourceAsStream() ? That gives you an input stream to the resource.
Your problem is that you are trying to create a FileInputStream to read from that resource, when you don't actually have a File to read from. Just use the InputStream that the getResourceAsStream() method returns.
We do have somebody here at work who speaks Polish but fortunately I didn't ask her, I asked Google instead.
thanx for all your answers!
do *NOT* try to find out what my screen name means. because it does not mean anything;-)
and what does not mean anything cant be bad.. or can it?
anyway i am trying to run getResourceAsStream thanx for your help!
i will let you know what i manage to do with getResourceAsStream
if my next post is in polish, and contains many words matching more
or less my screen name, that should be a sign that i was not successfull
and that i need a new machine.
and new window.
greetings
pg
P.S.
what you should *NOT* do is to put that screen name
in goole search engine, especialy in images.
chujaa at 2007-7-14 17:45:54 >

> do *NOT* try to find out what my screen name means.
> what you should *NOT* do is to put that screen name
> n goole search engine, especialy in images.
A little late for those warnings, isn't it?
I'm glad I grew up with boys. I must be nearly impossible to offend, now.
you know what they say .. a road to hell is paved with google searches.. allthough i belive that this applies only to first few steps..sorry once more for that screen namepeter
chujaa at 2007-7-14 17:45:55 >

What in the heck happened here?
<h1>Forum tagging off?</h1>
i have not done anything!
chujaa at 2007-7-14 17:45:55 >

Don't worry about it. Sun upgraded again. Did getResourceAsStream work out?
i am trying.. but i guess it is not my day.. to day..as it comes to that i do not think yesterday was my day either..or the day before yesterday.. i do not recall .. any way. i am trying.i found out that this is the first time i am doing resources.
chujaa at 2007-7-14 17:45:55 >

ok!getResourcesAsStream solved my problem!thanx all!namely, thanx to (random order):cotton.mTuringPestDrClapcdelmio