Convert Zip To EXE

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

Convert Zip To 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.