Compress Data - CSharp File IO

CSharp examples for File IO:GZip

Description

Compress Data

Demo Code


using System;/*  w  w  w.j  a v  a2s . c o m*/
using System.IO;
using System.IO.Compression;

class MainClass
    {
        static void Main(string[] args)
        {
            GZipStream zipout = new GZipStream(File.OpenWrite("compressed_data.gzip"),CompressionMode.Compress);
            StreamWriter writer = new StreamWriter(zipout);

            writer.WriteLine("the quick brown fox");
            writer.Close();

            GZipStream zipin = new GZipStream(File.OpenRead("compressed_data.gzip"),CompressionMode.Decompress);
            StreamReader reader = new StreamReader(zipin);

            Console.WriteLine(reader.ReadLine());

        }
    }

Result


Related Tutorials