位置: 首頁 > IT認證 > JAVA認證

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

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

}

}

標籤:示例 JAVA JAVA 解壓縮 檔案
2016-06-12
2016-02-25
2016-10-23
2016-01-01
2016-04-10
2019-10-25
2016-02-25
2016-08-22
2016-06-12
2016-10-08

Copyright ©2024 才華齋 All Rights Reserved.