Compress File With GZip In Java
This example show you how to apply gzip compression to a file in Java.
Java supports both Zip and GZip compression out of the box. You do not need any third party components.
import java.io.*;
import java.util.zip.*;
public class GzipCompressor
{
public void Compress(String inputFile, String outputFile)
{
try
{
BufferedReader reader =
new BufferedReader(new FileReader(inputFile));
BufferedOutputStream output =
new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outputFile)));
int b;
while((b =reader.read()) != -1)
{
output.write(b);
}
reader.close();
output.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}
Top Posts
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Windows 7 Control Panel In Classic Mode
- More Details Emerge On Microsoft Master Certification
- Use SqlConnection With LINQ To SQL
- Capture XML In WCF Service
- Free Icons And Images With Visual Studio 2008
- Dynamic Sort With LINQ
- StyleCop Tutorial
Tags
.Net 2010 ADO.NET ASP.NET Azure Blogging Books Browsers C# Certification Cloud Computing Code Snippets Community Data Services Eclipse Entity Framework Google IDE Java LINQ Mac Microsoft Museum NetBeans Office Oracle REST SharePoint Silverlight SQL Server T-SQL Tips Tools Training Visual Studio Visual Studio 2010 WCF Web Windows Windows 7 Windows Forms Windows Live WMI WPF XAML

