Here is my code to zip up the files:
|
Code:
|
public void createZipFile(String[] source, String zipFileName) {
byte[] buf = new byte[18024];
try {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
for (int i=0; i<source.length; i++) {
FileInputStream in = new FileInputStream(source[i]);
out.putNextEntry(new ZipEntry(source[i]));
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
} |
and this is the code I use to read the xml in the zip file:
|
Code:
|
File propertyFile = new File (propertyFilePath);
FileInputStream fis = null;
try {
fis = new FileInputStream(propertyFile);
}
catch (IOException e){
System.out.println("Problem reading properties.xml: " + e);
} |
It throws an exception when I tried to read the xml file, a file that contains only a opening and closing tag. It says "de.schlichtherle.io.UpdatingArchiveController$Arc hiveEntryNotFoundException: C:\\temp\test.zipCategory/properties.xml: No such entry!". I printed out the absolute path to it and it was valid (C:\temp\test.zip\Category\properties.xml). I'm not sure what the problem is. Works fine when I use winzip to manually zip up these files.
Thanks!