Java direct read. zip compressed file (i)

Source: Internet
Author: User
Tags ming

Java does not understand compression directly read the. zip compressed File This example, the following demo of the project source generation download address is as follows:
Source code Download address

Package com.sd.test.readzip;
Import Java.io.BufferedInputStream;
Import Java.io.BufferedReader;
Import Java.io.FileInputStream;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
Import Java.util.zip.ZipEntry;
Import Java.util.zip.ZipFile;
Import Java.util.zip.ZipInputStream;  Note The default save to save the file as Utf-8,txt file is ANSI. To be changed to Urf-8, it would be like File:ziptestfile/fileinzip.txt public class Readzip {public static void
        Main (string[] args) throws IOException {//TODO auto-generated method stub readzip rz=new readzip ();
    Rz.readzipcontext ();
        The public void Readzipcontext () throws ioexception{String zippath= "Zipfile/ziptestfile.zip";

        ZipFile zf=new ZipFile (Zippath);
        InputStream in=new Bufferedinputstream (New FileInputStream (Zippath));
        Zipinputstream zin=new Zipinputstream (in);
        The ZipEntry class is used to represent a ZIP file entry.
        ZipEntry ze; while ((Ze=zin.getnextentry ())!=null) {if (Ze.isdirectory ()){//Empty folder does nothing}else{System.err.println ("File:" +ze.getname () + "\nsize:" +ze.
                GetSize () + "bytes");
                    if (Ze.getsize () >0) {BufferedReader reader;
                        try {reader = new BufferedReader (New InputStreamReader (Zf.getinputstream (Ze), "utf-8"));
                        String Line=null;
                        while ((Line=reader.readline ())!=null) {System.out.println (line);
                    } reader.close (); catch (IOException e) {//TODO auto-generated catch block E.printstackt
                    Race ();
 }
                }

            }
        }
    }
}

Output:
file:ziptestfile/fileinzip.txt
size:395bytes
1 zipе
2 jsonݣ{"age": "List": [ "One", "two"], "List1": [{"Age":], "name": "Xiao Ming", "Sex": "Boy", "strudent": true},{"Age": "Name": "Xiao", "" Sex ":" Girl "," Strudent ": true}]," map ": {" one ": {" age ":" Name ":" Xiao Ming "," Sex ":" Boy "," Strudent ": true}," two ": {" Age ":", "name": "Xiao", "Sex": "Girl", "Strudent": true}, "name": "Da June", "Sex": "Boy", "strudent": false, "student" : null}
3 sdfadh
File:ziptestfile/fileinzip1.txt
size:408bytes
1, text in Zip
2, JSON data: {"Age": 21, " List ": [" One "," two "]," List1 ": [{" Age ":" Name ":" Xiao Ming "," Sex ":" Boy "," strudent ": true},{" Age ":", "name": "Xiao "", "Sex": "Girl", "Strudent": "True}", "map": {"one": {"age": "Name": "Xiao Ming", "Sex": "Boy", "Strudent": true}, " Two ': {"age": "Name": "Xiao", "Sex": "Girl", "Strudent": "True}", "Name": "Da June", "Sex": "Boy", "strudent": false, " Student ': null}
3, Sdfadh

Related Article

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.