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

Java檔案解壓縮例項詳解2016

JAVA認證 閱讀(4.54K)

為了幫助廣大考試新手們更加順利地複習備考,小編整理了JAVA檔案解壓縮的相關例項,希望能夠對大家學習java有所幫助。

Java檔案解壓縮例項詳解2016

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!");

}

}