ZipFile(File file) Opens a ZIP file for reading given the specified File object.ZipFile(File file, int mode) Opens a new ZipFile to read from the specified File object in the specified mode.ZipFile(String name) Opens a zip file for reading.
download is not that simple,I try: response.setContentType("application/msexcel"); OutputStream os = response.getOutputStream(); response.setHeader("Content-disposition","attachment; filename=courseware.xls"); os.write(bytes); os.close();but can't effect
is there simple way to zip a dir and its recursive files
java.net.InetAddress.getLocalHost().getHostAddress()
3.
package com.bj.zk.util.comm;import java.util.*;
import java.sql.*;
import org.apache.log4j.Logger;
import java.util.zip.*;
import java.io.* ;//******************************************
/**
*字符串压缩和解压缩
*@author 常通多维CTDW
*@version 2003.07.12
*/
//******************************************public class ZipAndUnzip{
static Logger logger = Logger.getLogger(ZipAndUnzip.class.getName());
/**
* 字符串压缩
*@param String 被压缩字符串
*@exception exception 例外错误
*/
public void stringZip(String strXml)throws Exception{ byte[] bt;
bt=strXml.getBytes();
//在此路径生成ZIP文件target.zip
FileOutputStream fs = new FileOutputStream("C:/target.zip");
ZipOutputStream zipStream = new ZipOutputStream(fs);
try{
//创建target.zip的tableData.mxl被压缩文件
ZipEntry entry = new ZipEntry("tableData.xml");
//写数据到tableData.mxl
zipStream.putNextEntry(entry);
for(int i=0;i<bt.length/1000;i++){
zipStream.write(bt,i*1000,1000);
}
zipStream.write(bt,(bt.length/1000)*1000,bt.length-(bt.length/1000)*1000);
}catch(Throwable t){logger.info(t.toString());}
zipStream.close();
fs.close();
}
/**
* 字符串解压缩
*@return String 解压缩后字符串
*@exception exception,Throwable 例外错误
*/
public String stringUnzip()throws Exception,Throwable{
String st="";
try{
//被解压缩文件C:/target.zip
ZipFile zf=new ZipFile("C:/target.zip");
Enumeration e=zf.entries();
ZipEntry ze=(ZipEntry)e.nextElement();
//文件大小
int size=0;
size=(int)ze.getSize();
zf.close(); FileInputStream fis=new FileInputStream("C:/target.zip");
ZipInputStream zis=new ZipInputStream(fis);
ZipEntry entry = null;
entry=zis.getNextEntry();
//解成byte[]
byte[] b=new byte[size];
int rb=0;
int chunk=0;
while ((size - rb) > 0) {
chunk=zis.read(b,rb,size - rb);
if (chunk==-1) {
break;
}
rb+=chunk;
}
st=new String(b);
zis.close();
fis.close(); }catch(Throwable t){
logger.info(t.toString());
throw t;
}
return st;
}
}
Opens a ZIP file for reading given the specified File object.ZipFile(File file, int mode)
Opens a new ZipFile to read from the specified File object in the specified mode.ZipFile(String name)
Opens a zip file for reading.
OutputStream os = response.getOutputStream();
response.setHeader("Content-disposition","attachment; filename=courseware.xls");
os.write(bytes);
os.close();but can't effect