2012-04-12 93 views
3

私はzt-zipをゼロ回しで使用しています。圧縮すると、開いてみると破損しています。何か案は? http://pastie.org/3773634Javaが破損したZIPファイルを作成しています

+2

なぜなら、java.util.zipを使用しないのはなぜですか? –

+0

再現可能なテストケースを貼り付けてください(pastebin.comなどにコードを貼る可能性があります)。テストケースがなければ、私たちが手助けすることはほとんどありません。 – sleske

+0

私はこれで長い間苦労してきました。私はこれを使うことにしました。 – cheese5505

答えて

3

ZipUtil.pack(new File("C:\\Users\\David"), new File(zipName)); は、Javaクラス

輸入のjava.util.zip.ZipFile、次の直接使用することができますZipファイルを作成するには、

// These are the files to include in the ZIP file 
String[] filenames = new String[]{"filename1", "filename2"}; 

// Create a buffer for reading the files 
byte[] buf = new byte[1024]; 

try { 
    // Create the ZIP file 
    String outFilename = "outfile.zip"; 
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename)); 

    // Compress the files 
    for (int i=0; i<filenames.length; i++) { 
     FileInputStream in = new FileInputStream(filenames[i]); 

     // Add ZIP entry to output stream. 
     out.putNextEntry(new ZipEntry(filenames[i])); 

     // Transfer bytes from the file to the ZIP file 
     int len; 
     while ((len = in.read(buf)) > 0) { 
      out.write(buf, 0, len); 
     } 

     // Complete the entry 
     out.closeEntry(); 
     in.close(); 
    } 

    // Complete the ZIP file 
    out.close(); 
} catch (IOException e) { 
} 
+0

私はこれまでのようなものを使ってきましたが、それはいつも私に壊れたファイルを与えます。 – cheese5505

+0

とにかく試してみよう... – cheese5505

+0

私はそれを試したが、それはZIPファイルを作成したが、何も追加しなかった。 – cheese5505

関連する問題