ZIP压缩后里面会有很多文件夹,能否取当前文件夹的
用ZIP包压缩一个文件后,所产生的压缩包里面有很多一级级的文件夹(貌似原先文件所在绝对路径所包含的一个个文件夹),能否达到压缩包里面就只有需要压缩的文件,或者只取一个文件夹,而不是这样N多的文件夹互相包含。我的代码如下
---------------------------------------------------------
String path = request.getRealPath(""); //取得当前目录的路?
byte b[] = new byte[512];
ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(path +
"../platformtab_zip/test.zip"));
String args[] = {
path + "../platformtab_zip/200612211166688343828.xls",
path + "../platformtab_zip/0200612211166688427453.doc",
path + "../platformtab_zip/2200612211166688427468.xls",
path + "../platformtab_zip/2200612211166688123421.doc"};
for (int i = 0; i < args.length; i++) {
InputStream in = new FileInputStream(args[i]);
ZipEntry e = new ZipEntry(args[i].replace(File.separatorChar, '/'));
zout.putNextEntry(e);
int len = 0;
while ( (len = in.read(b)) != -1) {
zout.write(b, 0, len);
}
zout.closeEntry();
}
zout.close();