The elusive Java uncompressed file error

Source: Internet
Author: User

Write a uncompressed class with the following code: Mport java.io. * ;
Import Java.util.zip. * ;

public class Unzipae ... {
static final int BUFFER = 2048;
Zipinputstream zis = null;
String outputdirectory = new string ();

public void Openzipfile (String fileName)
... {
Try
... {
ZiS = new Zipinputstream (
New Bufferedinputstream (
New FileInputStream (FileName));
}
catch (Exception e)
... {
System.out.println (e);
}
}

public void Setoutputdirectory (String directory)
... {
outputdirectory = Directory;
}

public void Unzipfile ()
... {
byte [] barray = new byte [2048];
int len = 2048, CT;
ZipEntry entry;
Try
... {
while ((entry = Zis.getnextentry ())!= null)
... {
FileOutputStream fout = new FileOutputStream (outputdirectory + "/" + entry.getname ());
Bufferedoutputstream bout = new Bufferedoutputstream (Fout, Len);
while (ct = zis.read (barray, 0, Len))!=-1)
... {
Bout.write (barray, 0, CT);
}
Bout.flush ();
Fout.close ();
Bout.close ();
}
Zis.close ();
}
catch (Exception e)
... {
System.out.println (e);
}
}
}

But after writing a test program to run it, the problem came. Unzipae Uzp = new Unzipae ();
Uzp.openzipfile ("D:/test.zip");
Uzp.setoutputdirectory ("D:/output");
Uzp.unzipfile ();

After running, incredibly reported abnormal illegalargumentexception, set breakpoints debugging, found that the exception is in entry = Zis.getnextentry () thrown. I faint, this kind of abnormal how to debug. After a long day of depression, I began to wonder if there was a problem with the compressed file because it was all Chinese-named files in the package, so I changed a zip compression package. The files in the package are all named in English. Test run, everything is OK. HALO!!!! Does Java not support extracting zip files that contain Chinese file names?

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.