Home Java Java-conversion Convert Zip To EXE



Convert Zip To EXE
Posted on: March 14, 2008 at 12:00 AM
In this example we are going to convert a zipped file into exe.

Convert Zip To EXE

     

In this example we are going to convert a zipped file into exe.

To convert a Zip file into .exe file pass the name of a zip file using command line arguments. Use FileInputStream  to take the zipped file as input. Read the file from the system, unzip the file and store the data of this file into a byte array. Create another file with .exe extension. Write the byte formatted data of the unzip file into .exe file.  

Create FileOutputStream object pass the name of file with .exe extension for creating an exe file. ZipInputStream allows modification on zipped (or unzipped) file. Use getNextEntry() method to set the entry point of the zip file. Create an array of bytes which stores the data of unzipped file and finally write the data into exe file.

Here is the code of the program :

import java.io.*;
import java.awt.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.io.*;
import java.util.zip.*;
public class  ZipToEXE

public static void main(String arg[])throws Exception
  {  
  OutputStream out=new FileOutputStream
(
"pdfFile.exe");
  ZipInputStream  zip = new ZipInputStream
(
new BufferedInputStream(new FileInputStream(arg[0])));
  ZipEntry entry;
  while((entry = zip.getNextEntry()) != null)
  {
  byte data[]=new byte[1024];
  int count;
  while((count=zip.read(data,0,1024))!=-1)
  {
  out.write(data,0,count);
  
  
  out.flush();
  out.close();
  }
}

Download this example.

Related Tags for Convert Zip To EXE:
ccomfilearrayormdataforminputobjectconvertiozipmethodformatoutputargumentsgetextensionstreamsystemcommandipreadnameusingbyteintlinethissetwriteexecreateinputstreamifforpoiexamplefinalwithunziptopointbytesexamstorefinallyargumentwsexteilitnotcommaliputusepemodificationoutputstreammanfrominnomodrmpassasmntoutnexttrcajadesementryallpiinputsmeintoobjmodippcatfileinputstreamcreatingsystorxawhichxamptrysxeformattedatpinkisippllmplrayfileoutputstreamgoeaandarstrrtxtzipinputstreamtstreamttzssrithst.exeatifileoutputfileinputfinjeicaicaoutputspleplndonomonp


More Tutorials from this section

Ask Questions?    Discuss: Convert Zip To EXE  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.