Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners how to create .exe file of java application??

Have Programming Question? Ask it here!
 
 
 


raghvendra kumar
how to create .exe file of java application??
2 Answer(s)      5 years ago
Posted in : Java Beginners



Advertisement
View Answers

July 30, 2009 at 10:05 AM


Hi Friend,

Try the following code:

import java.io.*;
import java.util.jar.*;

public class CreateJar {
public static int buffer = 10240;
protected void createJarArchive(File jarFile, File[] listFiles) {
try {
byte b[] = new byte[buffer];
FileOutputStream fout = new FileOutputStream(jarFile);
JarOutputStream out = new JarOutputStream(fout, new Manifest());
for (int i = 0; i < listFiles.length; i++) {
if (listFiles[i] == null || !listFiles[i].exists()|| listFiles[i].isDirectory())
System.out.println("-----------------------------------");
System.out.println("Adding " + listFiles[i].getName());
JarEntry addFiles = new JarEntry(listFiles[i].getName());
addFiles.setTime(listFiles[i].lastModified());
out.putNextEntry(addFiles);

FileInputStream fin = new FileInputStream(listFiles[i]);
while (true) {
int len = fin.read(b, 0, b.length);
if (len <= 0)
break;
out.write(b, 0, len);
}
fin.close();
}
out.close();
fout.close();
System.out.println("Jar File is created successfully.");
} catch (Exception ex) {}
}
public static void main(String[]args){
CreateJar jar=new CreateJar();
File folder = new File("c://Answers//Database";);
File[] files = folder.listFiles();
File file=new File("C://Answers//DataBase//DataBaseExamples.jar";);
jar.createJarArchive(file, files);
}

}

Thanks


June 22, 2012 at 12:35 AM


Thanks Dear,

I tested the program and it's running without any error ....

Pramoj



Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com