Java read zip file Java Read compressed file extract zip inside the specified format file
Source: Internet
Author: User
On the internet to see a lot of examples, the result is very disappointing, so decided to write an example, to provide you with reference to study; no more nonsense. See examples directly:
private static void execute (ZipEntry ze, inputstream read,string saverootdirectory)
Throws FileNotFoundException, IOException {
If you only read the picture, make your own decision OK.
String fileName = Ze.getname ();
if (Filename.lastindexof (". jpg")!=-1 | | | filename.lastindexof (". bmp")!=-1
// || Filename.lastindexof (". jpeg")!=-1) {//Specify the file format to extract (these formats can be extracted in a collection or string array via parameter passing in, method more general)
File File = new file (saverootdirectory + fileName);
if (!file.exists ()) {
File Rootdirectoryfile = new file (File.getparent ());
Create a table of contents
if (!rootdirectoryfile.exists ()) {
Boolean ifsuccess = Rootdirectoryfile.mkdirs ();
if (ifsuccess) {
System.out.println ("Folder creation successful!");
} else {
System.out.println ("File creation failed!");
}
}
Create a file
try {
File.createnewfile ();
catch (IOException e) {
E.printstacktrace ();
}
}
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.