亚洲精品中文字幕无乱码_久久亚洲精品无码AV大片_最新国产免费Av网址_国产精品3级片

JAVA認(rèn)證

Java文件解壓縮實(shí)例詳解

時(shí)間:2024-06-20 01:14:56 JAVA認(rèn)證 我要投稿
  • 相關(guān)推薦

Java文件解壓縮實(shí)例詳解2016

  為了幫助廣大考試新手們更加順利地復(fù)習(xí)備考,小編整理了JAVA文件解壓縮的相關(guān)實(shí)例,希望能夠?qū)Υ蠹覍W(xué)習(xí)java有所幫助。

  Java實(shí)現(xiàn)壓縮文件的解壓縮操作,缺點(diǎn)是壓縮文件內(nèi)不能含有文件名為中文的的文件,否則會(huì)出現(xiàn)如下錯(cuò)誤:

  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("開(kāi)始解壓縮" + 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) {

  //System.out.println(temp);

  out.write(temp);

  }

  input.close();

  out.close();

  }

  System.out.println("Done!");

  }

  }

【Java文件解壓縮實(shí)例詳解】相關(guān)文章:

JAVA認(rèn)證基礎(chǔ)知識(shí):Java文件解壓縮示例06-11

Java的壓縮與解壓縮ZIP11-01

Linux解壓縮命令詳解201608-11

關(guān)于JAVA實(shí)現(xiàn)httpClient的實(shí)例11-05

Java讀取xml文件的方法10-10

JQuery菜單效果實(shí)例詳解06-09

word 文檔域應(yīng)用實(shí)例詳解09-20

C盤(pán)系統(tǒng)文件作用詳解09-08

javascript 單例模式詳解及簡(jiǎn)單實(shí)例07-08

JavaScript中push(),join() 函數(shù)實(shí)例詳解05-30