1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
private boolean createZIP(List list, String strOutputFileName) {
    byte[]          buffer  = new byte[2048];
 
    try {
        ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(strOutputFileName));
        String  strFileName = "";
  
        for (int i=0; i<list.size(); i++){
            strFileName = (String) list.get(i);
            strFileName = strFileName.substring(12);
             
            File f  = new File(uploadPath + File.separator + strFileName);
            FileInputStream fin = new FileInputStream(f);
     
            ZipEntry ze = new ZipEntry(f.getName());
            ze.setTime( f.lastModified() );
            zout.putNextEntry(ze);
             
            int nlen    = 0;
            while( (nlen = fin.read(buffer) ) > 0) {
                zout.write(buffer, 0, nlen);
            }
            zout.closeEntry();
            fin.close();
        }
        zout.close();
        return true;
    }
    catch (IOException e)
    {
        e.printStackTrace();
        return false;
    }
}

+ Recent posts