壓縮的
import java
import java
import java
import java
import java
import java
import java
public class Zip {
static final int BUFFER =
public static void main(String argv[]) {
try {
BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream(
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(
dest));
byte data[] = new byte[BUFFER];
File f = new File(
File files[] = f
for (int i =
FileInputStream fi = new FileInputStream(files[i]);
origin = new BufferedInputStream(fi
ZipEntry entry = new ZipEntry(files[i]
out
int count;
while ((count = origin
out
}
origin
}
out
} catch (Exception e) {
e
}
}
}
import java
import java
import java
import java
import java
import java
import java
public class UnZip {
static final int BUFFER =
public static void main(String argv[]) {
try {
String fileName =
String filePath =
ZipFile zipFile = new ZipFile(fileName);
Enumeration emu = zipFile
int i=
while(emu
ZipEntry entry = (ZipEntry)emu
//會把目錄作為一個file讀出一次
if (entry
{
new File(filePath + entry
continue;
}
BufferedInputStream bis = new BufferedInputStream(zipFile
File file = new File(filePath + entry
//加入這個的原因是zipfile讀取文件是隨機讀取的
//而這個文件所在的目錄還沒有出現過
File parent = file
if(parent != null && (!parent
parent
}
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos
int count;
byte data[] = new byte[BUFFER];
while ((count = bis
{
bos
}
bos
bos
bis
}
zipFile
} catch (Exception e) {
e
}
}
}
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19246.html