Java文件解压缩示例
- JAVA认证
- 关注:1.66W次
新一批的考生已经开始备战2016年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!");
}
}
- 文章版权属于文章作者所有,转载请注明 https://xuezhezhai.com/itrz/java/qdqxnr.html