如题 ,希望能详细点!!
解决方案 »
- 登陆弹出窗口登陆不对后显示错误信息
- Exception starting filter struts2
- sequoia数据库集群中间件解析空格的问题
- 系统整合/跨系统数据共享
- jxl导出excel有时候行有时候不行
- JDBC的连接问题
- 怎么才能使 Dreamweaver UltraDev 4 写jsp时自动完成功能就像jb一样
- Connection Pool 不能正常回收 Connection
- 高分,如何才能支持EJB2,解决再给100分
- EJB问题: CMP的home接口中可否自己定义一些方法, 完成一些cmp不能做的事情,如MaxXxx().
- java连接oracle问题
- jquery 插件 tablesort 对表格排序问题
File newFile = new File(compressFileName);
if (newFile.exists()) {
newFile.delete();
}
newFile.createNewFile();
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(newFile));
byte[] data = new byte[1024];
ZipEntry entry = new ZipEntry(originalFileName);
zipOut.putNextEntry(entry);
int n;
while (-1 != (n = inputStream.read(data))) {
zipOut.write(data, 0, n);
}
zipOut.close();
}希望对你有所帮助,很简单,没什么其它功能
*
* @param inputFileName
* 输入一个文件夹
* @param zipFileName
* 输出一个压缩文件夹,打包后文件名字
* @throws Exception
*/
public void zip(String inputFileName, String zipFileName) throws Exception {
zip(zipFileName, new File(inputFileName));
}
private void zip(String zipFileName, File inputFile) throws Exception {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
zip(out, inputFile, "");
out.close();
}
private void zip(ZipOutputStream out, File f, String base) throws Exception {
/*读取进度*/
if (f.isDirectory()) { // 判断是否为目录
File[] fl = f.listFiles();
out.putNextEntry(new org.apache.tools.zip.ZipEntry(base + "/"));
base = base.length() == 0 ? "" : base + "/";
for (int i = 0; i < fl.length; i++) {
showSize += fl[i].length();
setMsg("已压缩" + (showSize * 100 / totalSize ) + "%......", false);
zip(out, fl[i], base + fl[i].getName());
}
} else { // 压缩目录中的所有文件
out.putNextEntry(new org.apache.tools.zip.ZipEntry(base));
FileInputStream in = new FileInputStream(f);
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
in.close();
}
}
是我显示进度条的