Compressing a File with MS Visual J# .NET

Compressing a File with MS Visual J# .NET

The Microsoft Visual J# .NET 1.1 Class Library (vjslib.dll) contains methods you can use to compress a file. The following code demonstrates how to use them.

/* Code to zip a file/folder using Visual J# library */using System;using System.IO;using;using java.util;using;namespace Zipper{ /// <summary> /// This Class provides methods to Zip a file vjslib /// c:windowsmicrosoft.netframeworkv1.1.4322vjslib.dll ///   public class Zipper {   #region Constructor     public Zipper(){}   #endregion Constructor		   #region Void Methods    /*CreateZipFile Method expects the path to be zipped.     * The path could be a directory or a single file*/   public void CreateZipFile(string sPath)   {     FileOutputStream stream1 = null;     ZipOutputStream stream2 = null;     if (System.IO.File.Exists(sPath))     {	FileInfo info2 = new FileInfo(sPath);        stream1 = new FileOutputStream(sPath.Replace                                      (info2.Extension, ".zip"));	stream2 = new ZipOutputStream(stream1);			this.ZipOneFile(stream1, stream2,  sPath);     }     else if (Directory.Exists(sPath))     {	stream1 = new FileOutputStream(sPath + ".zip");	stream2 = new ZipOutputStream(stream1);	DirectoryInfo info1 = new DirectoryInfo(sPath);	this.ZipDirectory(stream1, stream2, info1, sPath);     }     stream2.close();     stream1.close();     stream2.flush();     stream1.flush();    }    private void CopyStream(FileInputStream src, ZipOutputStream                                                             dest)    {	InputStreamReader reader1 = new InputStreamReader(src);	OutputStreamWriter writer1 = new OutputStreamWriter(dest);	while (reader1.ready())	{	  writer1.write(;	}	writer1.flush();    }		    /*ZipDirectory Method zips the entire directory*/    private void ZipDirectory(FileOutputStream fos, ZipOutputStream                              zos, DirectoryInfo di, string SRootDir)    {	FileInfo[] infoArray2 = di.GetFiles();	foreach (FileInfo info2 in infoArray2)	{           ZipEntry entry1 = new ZipEntry               (info2.FullName.Substring(SRootDir.LastIndexOf(@"")));	   entry1.setMethod(8);	   zos.putNextEntry(entry1);	   FileInputStream stream1 = new FileInputStream                                       (info2.FullName);       	   this.CopyStream(stream1, zos);	   zos.closeEntry();	   stream1.close();	}	DirectoryInfo[] infoArray1 = di.GetDirectories();	foreach (DirectoryInfo info1 in infoArray1)	{	   this.ZipDirectory(fos, zos, info1, SRootDir);	}     }     /*ZipOneFile Method zips the file*/     private void ZipOneFile(FileOutputStream fos, ZipOutputStream                                              zos, string sFullName)     {	ZipEntry entry1 = new ZipEntry(sFullName.Substring                            (sFullName.LastIndexOf(@""))); 	entry1.setMethod(8);	zos.putNextEntry(entry1);	FileInputStream stream1 = new FileInputStream(sFullName);	this.CopyStream(stream1, zos);	zos.closeEntry();	stream1.close();     }     #endregion Void Methods  }}
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes