读书人

关于使用JAVA.util.zip压缩文件后,解压

发布时间: 2012-11-07 09:56:10 作者: rapoo

关于使用JAVA.util.zip压缩文件后,解压缩时出现文件名乱码的解决办法

//使用org.apache.tools.zip包  public void ExportRARTest(String tablename[],HttpServletRequest request,String dir,String fileFolder,String isback) throws IOException{   byte[] buf = new byte[1024];       org.apache.tools.zip.ZipOutputStream out = new org.apache.tools.zip.ZipOutputStream(new FileOutputStream(dir));       String pathString="";       if ("yes".equals(isback)) {pathString=fileString+fileFolder;}       else {pathString=request.getRealPath("/")+"updbload";}       try {       for(int i=0;i<tablename.length;i++) {       tablename[i]=pathString+"/"+tablename[i];       File file=new File(tablename[i]);       if (file.exists()) {           FileInputStream fis = new FileInputStream(file);           out.putNextEntry(new org.apache.tools.zip.ZipEntry(file.getName()));           int len;           //读入需要下载的文件的内容,打包到zip文件          while((len = fis.read(buf))>0) {           out.write(buf,0,len);           }           out.closeEntry();           fis.close();           file.delete();       }       }} catch (Exception e) {// TODO: handle exceptione.printStackTrace();}      finally{        out.close();      }}注意黑体<Strong></Strong>部分是解决中文乱码的关键!!!!!!

?

读书人网 >编程

热点推荐