Use J # runtime in C # To Compress and decompress

Source: Internet
Author: User

Introduction

There are many class libraries available for zip files. I found it very easy to operate zip files in C # programs. When Microsoft's. NET framework 1.1 came out, a new language called J # was also released #. Let's take a look at J. Java is the front of the July language. If this is the case, java.util.zip can be used here. It took me some time to find it in vjslib. dll. Let's use it. Create a new C # project and select a Windows application. We can do this as follows:

 

All we need to do is add reference.


After adding a reference, you can start.


// Output stream
Java. io. FileOutputStream fos = new java. io. FileOutputStream (zipFileName );

// Tie to zip stream
Java.util.zip. ZipOutputStream zos = new java.util.zip. ZipOutputStream (fos );

// Stream with source file
Java. io. FileInputStream FCM = new java. io. FileInputStream (sourceFile );

// It's our entry in zip
Java.util.zip. ZipEntry ze = new java.util.zip. ZipEntry (sourceFile );

Zos. putNextEntry (ze );
Sbyte [] buffer = new sbyte [2, 1024];
Int len;

// Read and write until done
While (len = FS. read (buffer)> = 0)
{
Zos. write (buffer, 0, len );
}
 
// Close everything
Zos. closeEntry ();
FCM. close ();
Zos. close ();
Fos. close ();

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.