JSP decompress rarfile program code

Source: Internet
Author: User

<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8"
Pageencoding = "UTF-8" %>
<% @ Page import = "Java. Io. *, java.util.zip. *" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> insert title here </title>
</Head>
<Body>
<%
Out. println (application. getrealpath ("/"));
%>
<Br/>
<%

Try {

Zipinputstream in = new zipinputstream (New fileinputstream (
Application. getrealpath ("/") + "1.zip "));

Zipentry entry = NULL;

While (Entry = in. getnextentry ())! = NULL ){

String entryname = entry. getname ();

If (entry. isdirectory ()){
File file = new file (application. getrealpath ("/") + entryname );
File. mkdirs ();
System. Out. println ("create folder" + entryname );
} Else {

Fileoutputstream OS = new fileoutputstream (application. getrealpath ("/")
+ Entryname );

// Transfer bytes from the ZIP file to the output file
Byte [] Buf = new byte [1, 1024];

Int Len;
While (LEN = in. Read (BUF)> 0 ){
OS. Write (BUF, 0, Len );
}
OS. Close ();
In. closeentry ();

}
}

} Catch (ioexception e ){
}
Out. println ("decompressed file succeeded ");
%>

</Body>
</Html>

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.