File fCreateFile = new File(sExportPath);
fCreateFile.mkdir();
生成文件夹
int iCounter = 0;
String[] files = fCreateFile.list();
while(files.length!=0) {
iCounter++;
log.debug("still waiting round " + iCounter);
Thread.sleep(1000);
}
判断文件夹是否为空
if (files.length!=0) { log.info("try to zip folder...");
try {
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(sExportPath + ".zip"));
Common.compressFolder(sExportPath,zos);
zos.close();
} catch (Exception e) {
log.info("create zip file error!");
}}如果文件夹不为零,生成zip文件,zip文件为零,为什么?
fCreateFile.mkdir();
生成文件夹
int iCounter = 0;
String[] files = fCreateFile.list();
while(files.length!=0) {
iCounter++;
log.debug("still waiting round " + iCounter);
Thread.sleep(1000);
}
判断文件夹是否为空
if (files.length!=0) { log.info("try to zip folder...");
try {
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(sExportPath + ".zip"));
Common.compressFolder(sExportPath,zos);
zos.close();
} catch (Exception e) {
log.info("create zip file error!");
}}如果文件夹不为零,生成zip文件,zip文件为零,为什么?
参考http://www.roseindia.net/java/example/java/io/ZipFolderExample.shtml
import java.io.*;
import java.util.zip.*;
public class ZipFolderExample
{
public static void main(String a[])
{
try
{
File inFolder=new File("out");
File outFolder=new File("Out.zip");
ZipOutputStream out = new ZipOutputStream(new
BufferedOutputStream(new FileOutputStream(outFolder)));
BufferedInputStream in = null;
byte[] data = new byte[1000];
String files[] = inFolder.list();
for (int i=0; i<files.length; i++)
{
in = new BufferedInputStream(new FileInputStream
(inFolder.getPath() + "/" + files[i]), 1000);
out.putNextEntry(new ZipEntry(files[i]));
int count;
while((count = in.read(data,0,1000)) != -1)
{
out.write(data, 0, count);
}
out.closeEntry();
}
out.flush();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}