Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help - How to Compress data using java.util.zip in C#.
Blog
 
# Tuesday, June 23, 2009

First add vjslib.dll from add reference link. Through this dll, we can compress data compatible with Java Compression.

Add Namespace into your class

using java.util.zip;
using java.util;
using java.io;

 

        /// <summary>
        /// This function is used to compress byte array data using java util.
        /// </summary>
        /// <param name="data">Byte Array Data</param>
        /// <param name="path">Path to Store compress File</param>
        /// <param name="fileName">File Name</param>
        public static void compressFileWrite(byte[] data, String path, String fileName)
        {

            try
            {
                java.io.File folder = new java.io.File(path + FORWARD_SLASH + ENCRYPT_OUTPUT_PATH);
                if (!folder.isDirectory())
                {
                    folder.mkdir();
                }
                java.io.File file = new java.io.File(folder.getPath() + FORWARD_SLASH + fileName);
                FileOutputStream fos = new FileOutputStream(file);
                DeflaterOutputStream dos = new DeflaterOutputStream(fos);
                dos.write((sbyte[])(Array)data);
                dos.close();
            }
            catch (java.io.FileNotFoundException Ex)
            {
                throw new Exception("Error while reading file \n" + Ex.Message);
            }
            catch (java.io.IOException Ex)
            {
                throw new Exception("Error in Compress File \n" + Ex.Message);
            }

        }

 This above code is compatible with java compression

Tuesday, June 23, 2009 11:49:36 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C#  | 
Comments are closed.
Copyright © 2010 SoftwareCodeHelp. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: