Java file uncompressed Implementation code _java

Source: Internet
Author: User

Java implementation of compressed file decompression operation, the disadvantage is that the compressed file can not contain files in Chinese file name, or the following error will occur:

Copy Code code as follows:

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)

Code:

Copy Code code as follows:

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 ("Start decompression" + entry.getname () +) file ... ");
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!");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.