文件名称:java压缩文件源码--ZipUtils
文件大小:2KB
文件格式:RAR
更新时间:2013-02-03 12:31:30
java,file,zip,util,java压缩文件
package com.hexiang.utils;
import java.io.*;
import java.util.*;
import java.util.zip.Adler32;
import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
public class ZipUtils {
private static final int BUFFER = 8192;
private static void log(String msg){
System.out.println (msg);
}
private static String getFileName(String filePath){
int index = filePath.indexOf(".");
return filePath.substring(0, index);
}
@SuppressWarnings("unused")
private static String getRootPath(String filePath){
int index = filePath.indexOf(".");
return filePath.substring(0, index);
}
public static void zip(String sourceFilePath){
File fileDir = new File(sourceFilePath);
if(fileDir.exists()){
log(fileDir.getPath()+" Starting Zip ...");
long startTime = System.currentTimeMillis();
doZip(fileDir);
long endTime = System.currentTimeMillis();
long costTime = endTime - startTime;
log("Zip Success!");
log("use time -- "+costTime+" millsec!");
}else{
log("can't find the File!");
}
}
public static void unZip(String zipFilePath){
File fileDir = new File(zipFilePath);
if(fileDir.exists()){
log(fileDir.getPath()+" Starting UnZip ...");
long startTime = System.currentTimeMillis();
doUnZip(fileDir);
long endTime = System.currentTimeMillis();
long costTime = endTime - startTime;
log("UnZip Success!");
log("use time -- "+costTime+" millsec!");
}else{
log("can't find the File!");
}
}
public static void doZip(File file){
List
【文件预览】:
ZipUtils.java