當前位置:才華齋>IT認證>JAVA認證>

JAVA認證基礎知識:Java檔案解壓縮示例

JAVA認證 閱讀(2.74W)

Java實現壓縮檔案的解壓縮操作,缺點是壓縮檔案內不能含有檔名為中文的`的檔案,否則會出現如下錯誤:

JAVA認證基礎知識:Java檔案解壓縮示例

Exception in thread "main" galArgumentException: MALFORMED

at ring(Unknown Source)

at LOC(Unknown Source)

at extEntry(Unknown Source)

at ()

程式碼

package ;

import ;

import InputStream;

import OutputStream;

import tStream;

import utStream;

import ntry;

import ile;

import nputStream;

public class ZipFileDemo {

@SuppressWarnings("resource")

public static void main(String args[]) throws Exception {

File file = new File("d:" + rator + "");

File outFile = null;

ZipFile zipFile = new ZipFile(file);

ZipInputStream zipInput = new ZipInputStream(new FileInputStream(file));

ZipEntry entry = null;

InputStream input = null;

OutputStream out = null;

while ((entry = extEntry()) != null) {

tln("開始解壓縮" + ame() + "檔案。。。");

outFile = new File("d:" + rator + ame());

if (!arentFile()ts()) {

arentFile()r();

}

if (!ts()) {

teNewFile();

}

input = nputStream(entry);

out = new FileOutputStream(outFile);

int temp = 0;

while ((temp = ()) != -1) {

//tln(temp);

e(temp);

}

e();

e();

}

tln("Done!");

}

}