Computer Science Canada

read file out of jar

Author:  matt271 [ Wed Jun 17, 2009 5:46 pm ]
Post subject:  read file out of jar

in java how do u read a file out of its own jar?

say u made some program in netbeans and had netbeans package it into a jar for u, but u also have an image say "image.jpg"

how can i open it like File("image.jpg"); is its in the JAR file itself, not in the same dir as the jar file??

ty

Author:  rizzix [ Wed Jun 17, 2009 7:19 pm ]
Post subject:  RE:read file out of jar

Code:

import java.io.*;
import java.util.jar.*;
 .
 .
 .
Jar jar = new Jar("<path to jar file>");
ZipEntry imgEntry = jar.getEntry("image.jpg");

InputStream in = jar.getInputStream(imgEntry);


: