The use of Zipinputstream

Source: Internet
Author: User;Importjava.awt.BorderLayout;ImportJava.awt.EventQueue;Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;;;Importjava.util.List;ImportJava.util.Scanner;;;ImportJavax.swing.JComboBox;ImportJavax.swing.JFileChooser;ImportJavax.swing.JFrame;ImportJavax.swing.JMenu;ImportJavax.swing.JMenuBar;ImportJavax.swing.JMenuItem;ImportJavax.swing.JScrollPane;ImportJavax.swing.JTextArea;ImportJavax.swing.SwingWorker; Public classZiptest { Public Static voidMain (string[] args) {Eventqueue.invokelater (NewRunnable () {@Override Public voidrun () {Ziptestframe frame=NewZiptestframe ();                Frame.setdefaultcloseoperation (Jframe.exit_on_close); Frame.setvisible (true);    }        }); }}classZiptestframeextendsJFrame { PublicZiptestframe () {Settitle ("Ziptest");                SetSize (Default_width, default_height); JMenuBar MenuBar=NewJMenuBar (); JMenu Menu=NewJMenu ("File"); JMenuItem OpenItem=NewJMenuItem ("Open");        Menu.add (OpenItem); Openitem.addactionlistener (NewActionListener () {@Override Public voidactionperformed (ActionEvent e) {JFileChooser chooser=NewJFileChooser (); Chooser.setcurrentdirectory (NewFile (".")); intR = Chooser.showopendialog (ziptestframe. This); if(r = =jfilechooser.approve_option) {Zipname=chooser.getselectedfile (). GetPath ();                    Filecombo.removeallitems ();                Scanzipfile ();                }            }        }); JMenuItem Exititem=NewJMenuItem ("Exit");        Menu.add (Exititem); Exititem.addactionlistener (NewActionListener () {@Override Public voidactionperformed (ActionEvent e) {system.exit (0);                }        });        Menubar.add (menu);                Setjmenubar (MenuBar); FileText=NewJTextArea (); Filecombo=NewJComboBox (); Filecombo.addactionlistener (NewActionListener () {@Override Public voidactionperformed (ActionEvent e) {loadzipfile (String) Filecombo.getselecteditem ());                }        });        Add (Filecombo, Borderlayout.south); Add (NewJScrollPane (FileText),; }         Public voidScanzipfile () {NewSwingworker<void, string>() {@Overrideprotected voidProcess (list<string>names) {                 for(String name:names) {filecombo.additem (name); }} @OverrideprotectedVoid Doinbackground ()throwsException {zipinputstream Zin=NewZipinputstream (NewFileInputStream (zipname));                ZipEntry entry;  while((Entry = Zin.getnextentry ())! =NULL) {Publish (Entry.getname ());                Zin.closeentry ();                } zin.close (); return NULL;    }}.execute (); }         Public voidLoadzipfile (FinalString name) {filecombo.setenabled (false); Filetext.settext (""); NewSwingworker<void, void>() {@Overrideprotected voidDone () {filecombo.setenabled (true); } @OverrideprotectedVoid Doinbackground ()throwsException {Try{zipinputstream Zin=NewZipinputstream (NewFileInputStream (zipname));                                        ZipEntry entry;  while((Entry = Zin.getnextentry ())! =NULL) {                        if(Entry.getname (). Equals (name)) {Scanner in=NewScanner (Zin);  while(In.hasnextline ()) {Filetext.append (In.nextline ()); Filetext.append ("\ n");                    }} zin.closeentry ();                } zin.close (); } Catch(Exception e) {e.printstacktrace (); }                return NULL;    }}.execute (); }         Public Static Final intDefault_width = 400;  Public Static Final intDefault_height = 300; PrivateJComboBox Filecombo; PrivateJTextArea FileText; PrivateString zipname;}

The use of Zipinputstream

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: 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.