hi Waez,
check out the code i have given here.... if the filelength returns -1 u must try to read the data from the jar entry in chunks or set the filelength to some max value say 100 bytes.... replace temp.class with any file that u want to read
hope this code help you
import java.util.jar.*;
import java.io.*;
public class Readfromjar
{
public static void main(String[] args)
{
try {
FileInputStream fis = new FileInputStream ( "xxx.jar" );
JarInputStream j = new JarInputStream ( fis );
while ( true )
{
JarEntry entry = j.getNextJarEntry();
String elementName = entry.getName();
System.out.println(elementName);
if(elementName.equals("temp.class"))
{
File elementFile = new File("myfile");
int filelen = (int)entry.getSize();
//int filelen=100;
System.out.println(filelen);
byte[] wholeFile = new byte[ filelen ];
int bytesRead = j.read( wholeFile , 0 , filelen );
FileOutputStream fos = new FileOutputStream ( elementFile );
fos.write( wholeFile, 0, filelen );
fos.close();
j.closeEntry();
}
}
}
catch (IOException e) {
}
}
}