[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Jar Extraction Problem
- To: ajug-members@ajug.org
- Subject: Jar Extraction Problem
- From: "Jason R. Kretzer" <jason@OpinionOne.com>
- Date: Wed, 15 Jan 2003 11:56:32 -0500
- In-Reply-To: <02Dec20.100716est.119090@gdc2.dcor.state.ga.us>
- References: <02Dec20.100716est.119090@gdc2.dcor.state.ga.us>
- Reply-To: jason@OpinionOne.com
- User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2) Gecko/20021126
Hello all,
I am having a strange problem and I cannot find cause for it. I use the
method below to extract files from a jar. One of the files in the jar
has a '#' character in the file name. When I use the method below to
extract the files, all files come out ok except the one with the '#'
character in its name. Changing the file name in any way is not an
option. Is there any other way around this issue?
thanks,
-Jason
public boolean extractStudy(File[] fileList, String extDir)
{
try
{
JarFile aJar = new JarFile((getJarName().getPath()));
Enumeration enum = aJar.entries();
Enumeration echeck = aJar.entries();
echeck.nextElement();
enum.nextElement();
File dir = null;
JarEntry je = null;
InputStream is = null;
BufferedInputStream bi = null;
FileOutputStream fos = null;
BufferedOutputStream bo = null;
Vector elist = new Vector(1);
boolean inthere = false;
while(echeck.hasMoreElements())
{
elist.add(echeck.nextElement());
}
//go through each file, if necessary create any directories
needed and write the files
for(int i = 0; i < fileList.length; i++)
{
inthere = false;
String str = fileList[i].toString().trim();
for(int ec = 0; ec < elist.size(); ec++)
{
File f1 = new File(str);
File f2 = new File(getExtractionPath() + "\\" +
elist.get(ec).toString());
if(f1.equals(f2))
{
inthere = true;
}
}
if(!inthere)
{
dir = fileList[i].getParentFile();
dir.mkdirs();
fileList[i].mkdirs();
continue;
}
je = ((JarEntry) enum.nextElement());
System.out.println(je.toString());
is =
getClass().getClassLoader().getResourceAsStream(je.toString());
bi = new BufferedInputStream(is, 16384);
fos = new FileOutputStream(fileList[i]);
bo = new BufferedOutputStream(fos, 16384);
try
{
while(true)
{
byte[] byteArray = new byte[16384];
int intRead = bi.read(byteArray, 0,
byteArray.length);
bo.write(byteArray, 0, intRead);
bo.flush();
}
}
catch(Exception k)
{
//there will be exceptions so do nothing
}
if(verbose == 0)
{
System.out.println("Extracting file " + fileList[i]);
prg.update("Extracting: " + fileList[i]);
}
bi.close();
bo.close();
}
}
catch(ZipException zexc)
{
zexc.printStackTrace();
return false;
}
catch(FileNotFoundException fnfe)
{
fnfe.printStackTrace();
return false;
}
catch(IOException ioe)
{
ioe.printStackTrace();
return false;
}
return true;
}