How to copy a file from jar to disk

Hey guyz,

I have a client application that uses a wordprocessor. it needs a binary file in a folder e.g. c:/emp/processor/

the file is in my jar and i want to copy it to the location c:/temp/processor/

I loooked all over the net but could not find a *** thing.

The question is. How do i copy a file from my jar to the hard drive?

Thanks in advance.

[386 byte] By [S1lv3ra] at [2007-11-27 8:43:55]
# 1

Use the getResourceAsString method of Class to obtain the file as an InputStream, then use a FileOutputStream to create a new file, and use a loop reading and writing byte by byte from the above InputStream to the FileOutputStream until the end of the InputStream is reached, then close both Streams, and there you are.

The IO tutorial covering ByteStreams contains the exact loop you need.

And read the API (or Google) for the usage of the getResourceAsStream method.

masijade.a at 2007-7-12 20:44:29 > top of Java-index,Core,Core APIs...
# 2
Take a look at the JAR package (or ZIP) at: http://java.sun.com/javase/6/docs/api/java/util/jar/package-frame.html
kmangolda at 2007-7-12 20:44:29 > top of Java-index,Core,Core APIs...