大蛇丸攻打木叶:寻求*.docx,*.xlsx,*.pptx文件下载后变成.zip文件的解决办法

来源:百度文库 编辑:中财网 时间:2024/05/06 08:41:23
寻求*.docx,*.xlsx,*.pptx文件下载后变成.zip文件的解决办法
网上有说在web.xml中增加如下代码就可以了,但我添加后还是不行.
 
  docx
  application/vnd.openxmlformats-officedocument.wordprocessingml.document
 

 
  xlsx
  application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
 

 
  pptx
  application/vnd.openxmlformats-officedocument.presentationml.presentation
 

请大虾帮忙!

 

package com.sitinspring.zip.test;
import java.io.File;
import java.io.IOException;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
import de.schlichtherle.io.FileInputStream;
import de.schlichtherle.io.FileOutputStream;
public class MoreZip {
 public static void main(String[] args) { 
  File[] f={new File("D:/中文/我们.txt"),new File("D:/中文/他们.txt"),new File("D:/中文/你们.txt")};
  MoreZip.ZipFiles(f, new File("D:/你我他.zip"));
 }
/**
   * 压缩文件
   * @param srcfile File[]  需要压缩的文件列表
   * @param zipfile File    压缩后的文件
   */
 public static void ZipFiles(java.io.File[] srcfile, java.io.File zipfile) {
     byte[] buf = new byte[1024];
     try {
       // Create the ZIP file
       ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
       // Compress the files
       for (int i = 0; i < srcfile.length; i++) {
         FileInputStream in = new FileInputStream(srcfile[i]);
         // Add ZIP entry to output stream.
         out.putNextEntry(new ZipEntry(srcfile[i].getName()));
         // 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();
       System.out.println("压缩完成.");
     }
     catch (IOException e) {
       e.printStackTrace();
     }
   }
回复于:2010-09-06 13:55:32在servlet里增加

response.setContentType("application/msexcel");
response.setHeader("Content-Disposition", " filename=report.xls");
在servlet里增加

response.setContentType("application/msexcel");
response.setHeader("Content-Disposition", " filename=report.xls");