国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

Java 文件解壓縮實現代碼

2019-11-26 15:51:11
字體:
來源:轉載
供稿:網友

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

復制代碼 代碼如下:

Exception in thread "main" java.lang.IllegalArgumentException: MALFORMED
 at java.util.zip.ZipCoder.toString(Unknown Source)
 at java.util.zip.ZipInputStream.readLOC(Unknown Source)
 at java.util.zip.ZipInputStream.getNextEntry(Unknown Source)
 at com.javatest.techzero.gui.ZipFileDemo.main(ZipFileDemo.java:22)

代碼:

復制代碼 代碼如下:

package com.javatest.techzero.gui;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

public class ZipFileDemo {
 @SuppressWarnings("resource")
 public static void main(String args[]) throws Exception {
  File file = new File("d:" + File.separator + "test.zip");
  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 = zipInput.getNextEntry()) != null) {
   System.out.println("開始解壓縮" + entry.getName() + "文件。。。");
   outFile = new File("d:" + File.separator + entry.getName());
   if (!outFile.getParentFile().exists()) {
    outFile.getParentFile().mkdir();
   }
   if (!outFile.exists()) {
    outFile.createNewFile();
   }
   input = zipFile.getInputStream(entry);
   out = new FileOutputStream(outFile);
   int temp = 0;
   while ((temp = input.read()) != -1) {
   <SPAN style="WHITE-SPACE: pre"> </SPAN>//System.out.println(temp);
    out.write(temp);
   }
   input.close();
   out.close();
  }
  System.out.println("Done!");
 }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇安县| 英吉沙县| 高台县| 望都县| 英山县| 宿迁市| 娄烦县| 宁乡县| 醴陵市| 旌德县| 湘乡市| 翼城县| 崇左市| 康定县| 柳江县| 盐城市| 丰镇市| 十堰市| 三门县| 镇远县| 东台市| 林州市| 安新县| 东乌珠穆沁旗| 永靖县| 锡林郭勒盟| 两当县| 舒兰市| 九台市| 定安县| 将乐县| 通山县| 洪江市| 绵阳市| 澄迈县| 秀山| 新津县| 缙云县| 三河市| 招远市| 遂溪县|