Binary objects in jar file

B

bigbinc

Can you put binary objects in a jar file and load them. I have done
this with ImageIcons, and I just assume that you can do this with for
example, binary files(pdf/application-specific files). Is there some
already written code out there.
 
T

Tony Morris

bigbinc said:
Can you put binary objects in a jar file and load them. I have done
this with ImageIcons, and I just assume that you can do this with for
example, binary files(pdf/application-specific files). Is there some
already written code out there.

Yes, you load them as a resource, just as you do with an image.
You usually provide an absolute URI where the root is the top level
directory within the JAR.
You then obtain a java.io.InputStream and start reading.

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform
 
A

Andrew Thompson

"bigbinc"...
Can you put binary objects in a jar file and load them.

Yes. Try it. Put them in a .jar
file and use Class.getResource()
to get an URL.
url.getResourceAsStream()...

You should get your bytes back
exactly as you put them in there.

You can also trawl around jar
files by creating a JarFile object,
getting an enumeration of the entries
(inherited from ZipFile) and going
though them.
...Is there some
already written code out there.

Yes, often referred to as
'the core API'. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top