java解压缩一个压缩文件中包含多个文件的情况

java

 1

11 package com.testFile.test;

12

13 import java.io.File;

14 import java.io.FileInputStream;

15 import java.io.FileOutputStream;

16 import java.io.IOException;

17 import java.io.InputStream;

18 import java.io.OutputStream;

19 import java.util.zip.ZipEntry;

20 import java.util.zip.ZipFile;

21 import java.util.zip.ZipInputStream;

22

23 /**

24 * 〈一句话功能简述〉<br>

25 * 〈功能详细描述〉

26 *

27 * @author Pasier

28 * @see [相关类/方法](可选)

29 * @since [产品/模块版本] (可选)

30 */

31 public class ZipFileDemo3 {

32 public static void main(String[] args) throws IOException {

33 // 要被压缩的文件夹

34 String zipFileName = "D:" + File.separator + "javaIo" + File.separator + "hello.zip";

35 // 被解压到的目标文件夹

36 String newFileName = "D:" + File.separator + "javaIo" + File.separator + "decZip";

37 File file = new File(zipFileName);

38 File outFile = null;

39 ZipFile zipFile = new ZipFile(file);

40 ZipInputStream zipInput = new ZipInputStream(new FileInputStream(file));

41 ZipEntry entry = null;

42 InputStream input = null;

43 OutputStream output = null;

44 while ((entry = zipInput.getNextEntry()) != null) {

45 System.out.println("解压缩" + entry.getName() + "文件");

46 outFile = new File(newFileName + entry.getName());

47 if (!outFile.getParentFile().exists()) {

48 outFile.getParentFile().mkdir();

49 }

50 if (!outFile.exists()) {

51 outFile.createNewFile();

52 }

53 input = zipFile.getInputStream(entry);

54 output = new FileOutputStream(outFile);

55 int temp = 0;

56 while ((temp = input.read()) != -1) {

57 output.write(temp);

58 }

59 input.close();

60 output.close();

61 }

62 }

63

64 }

参考博客"javaIO的整理":http://www.cnblogs.com/rollenholt/archive/2011/09/11/2173787.html

结果如下:

以上是 java解压缩一个压缩文件中包含多个文件的情况 的全部内容, 来源链接: utcz.com/z/393762.html

回到顶部