public void writeZipFile(File to, String[] filenames,String comment, int compression_level)
throws IOException, FileNotFoundException
{
ZipOutputStream zip_out;
int i;
ZipEntry zip_entry;
File cur_file;
byte[] buffer;
CheckedInputStream crc_in; // an input stream with CRC32 calculation
int bytes_read = 0;
zip_out = new ZipOutputStream(new FileOutputStream(to));
zip_out.setLevel(compression_level);
zip_out.setComment(comment);
buffer = new byte[COPY_BUFFER_SIZE]; for ( i = 0; i < filenames.length; i++ ) {
zip_entry = new ZipEntry(filenames[i]); // create the zip entry for the current file
System.err.println("Getting file " + filenames[i]);
cur_file = this.getFile(filenames[i]); // get the file in the container
System.err.println("done " + filenames[i]);
zip_entry.setSize(cur_file.length()); // set the file length zip_out.putNextEntry(zip_entry); // get ready to write another file
crc_in = new CheckedInputStream(new FileInputStream(cur_file), new CRC32()); while ( (bytes_read = crc_in.read(buffer)) != -1 ) { // read while data is available
System.err.println("Read " + bytes_read + " bytes from file " + filenames[i]);
zip_out.write(buffer,0,bytes_read); // write out data read
}
zip_entry.setCrc(crc_in.getChecksum().getValue()); // set calculated CRC32 checksum
zip_out.closeEntry(); // close current entry
}
zip_out.flush();
zip_out.close(); // close zip stream and file
}
throws IOException, FileNotFoundException
{
ZipOutputStream zip_out;
int i;
ZipEntry zip_entry;
File cur_file;
byte[] buffer;
CheckedInputStream crc_in; // an input stream with CRC32 calculation
int bytes_read = 0;
zip_out = new ZipOutputStream(new FileOutputStream(to));
zip_out.setLevel(compression_level);
zip_out.setComment(comment);
buffer = new byte[COPY_BUFFER_SIZE]; for ( i = 0; i < filenames.length; i++ ) {
zip_entry = new ZipEntry(filenames[i]); // create the zip entry for the current file
System.err.println("Getting file " + filenames[i]);
cur_file = this.getFile(filenames[i]); // get the file in the container
System.err.println("done " + filenames[i]);
zip_entry.setSize(cur_file.length()); // set the file length zip_out.putNextEntry(zip_entry); // get ready to write another file
crc_in = new CheckedInputStream(new FileInputStream(cur_file), new CRC32()); while ( (bytes_read = crc_in.read(buffer)) != -1 ) { // read while data is available
System.err.println("Read " + bytes_read + " bytes from file " + filenames[i]);
zip_out.write(buffer,0,bytes_read); // write out data read
}
zip_entry.setCrc(crc_in.getChecksum().getValue()); // set calculated CRC32 checksum
zip_out.closeEntry(); // close current entry
}
zip_out.flush();
zip_out.close(); // close zip stream and file
}
用你给出的代码进行压缩后,中文文件名出现乱码,注释也乱