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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Anoop Kumar
Java Steps
1 Answer(s)      5 years and 4 months ago
Posted in : Java Beginners



Advertisement
View Answers

September 10, 2009 at 5:35 PM


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//Examples";);
File[] files = folder.listFiles();
File file=new File("C://Answers//Examples//examples.exe";);
jar.createJarArchive(file, files);
}

}

Hope that it will be helpful for you.
Thanks


Related Tutorials/Questions & Answers:
Java Steps - Development process
Java Steps  what are the steps to be taken to create a mobile phone compatible java swing program
Java Steps - Java Beginners
Java Steps  How to create Execuateable EXE File of Java Program.  Hi Friend, Try the following code: import java.io.*; import java.util.jar.*; public class CreateJar { public static int buffer = 10240
Advertisements
Java Problem Steps - Swing AWT
Java Problem Steps  How to create a Jar File From the Dos prompt of a Swing program having two classes in the program with one is public class one of them
Steps not found.
Steps not found.  import java.io.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; public class Details1 extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse
steps to create desktop application in java swing using eclipse with drag and drop options
steps to create desktop application in java swing using eclipse with drag and drop options  please help to create desktop application in java swing using eclipse with drag and drop and what are the plugins required
I want simple steps to create Jar File of Java Project - Java Beginners
I want simple steps to create Jar File of Java Project  Hello Sir How I can Create Jar File of Java Project,plz Help Me  Hi Friend, Steps: 1. Start Command Prompt. 2. Navigate to the folder that holds your
Explain the process of implementing a CORBA client using a Java programming example and the steps involved.
Explain the process of implementing a CORBA client using a Java programming example and the steps involved.  plz tell me answer of this question... the process of implementing a CORBA client using a Java programming example
what are the steps in jdbc?
what are the steps in jdbc?  what are the steps in jdbc
Steps for the payment gateway processing?
Steps for the payment gateway processing?  Steps for the payment gateway processing
Steps to log4j configuration in Struts2
Steps to log4j configuration in Struts2  Hi... any tel me each step for configure log4j in struts2 application
Basic Steps to Outsourcing Success, Steps to Success in Outsourcing
Basic Steps to Outsourcing Success Introduction There are a few fundamental steps to ensure the best results for your outsourcing venture. These strategies... the decision making process in-house, these are the steps that need to be followed
steps to install jasper in Eclipse with example
steps to install jasper in Eclipse with example   steps to install jasper in Eclipse with example
steps to install jasper in Eclipse with example
steps to install jasper in Eclipse with example   steps to install jasper in Eclipse with example
steps to install jasper in Eclipse with example
steps to install jasper in Eclipse with example   steps to install jasper in Eclipse with example
steps required to execute a query in JDBC
steps required to execute a query in JDBC  What are the steps required to execute a query in JDBC
steps to upgrade cPanel MySQL 5.1 to 5.5
steps to upgrade cPanel MySQL 5.1 to 5.5   steps to upgrade cPanel MySQL 5.1 to 5.5
steps to upgrade mysql 5.1 to 5.5 mac
steps to upgrade mysql 5.1 to 5.5 mac  steps to upgrade mysql 5.1 to 5.5 mac
program that uses while loops to perform the following steps :
program that uses while loops to perform the following steps :  Write a program that uses while loops to perform the following steps : a. Prompt... inclusive f. Output all the uppercase letters. (java coding: pls help me
Steps to execue jsp in jcreator - Development process
Steps to execue jsp in jcreator  Hi Friends, Can anyone give steps for executing jsp and servlets using Jcreator IDE
Deployment steps in weblogic 102 - Development process
Deployment steps in weblogic 102   Hi Friends, can u give me d deployment steps in weblogic server 10.2(both jsp and servlet ..... how to export war file?) ..Thank u in advance
Deployment Steps in Weblogic Server - Development process
Deployment Steps in Weblogic Server  Hi Friends, Can anyone give me steps for Deploying application in web logic server ( both versions 8.1 and 9.2 ) with Eclipse IDE
Steps For SSL Implementation/Enabling in Apache Tomcat 6.0
Steps For SSL Implementation/Enabling in Apache Tomcat 6.0   Hi , I am using the NetBeans 6.9 IDE Apache Tomcat 6.0 as Web server Front end jsp-servlet please gives me complete guidance steps ,code for SSL Implementation
Steps For SSL Implementation/Enabling in Apache Tomcat 6.0
Steps For SSL Implementation/Enabling in Apache Tomcat 6.0   Hi , I am using the NetBeans 6.9 IDE Apache Tomcat 6.0 as Web server Front end jsp-servlet please gives me complete guidance steps ,code for SSL Implementation
JDBC Steps ? Basic steps in writing a JDBC Application
JDBC Steps – Basic steps in writing a JDBC Application... you brief description of JDBC Steps for making connection with the database.... Here are the JDBC Steps to be followed while writing JDBC program
Steps to Success in Offshore Outsourcing,Ten Successful Steps in Offshore Outsourcing
Offshore Outsourcing - Ten Steps to Success Here are a few must-follow steps when you go for offshore outsourcing. These steps are very useful in selecting a suitable vendor and planning out the entire process. The first step
pls provide steps to connect mysql in flex - XML
pls provide steps to connect mysql in flex   hi ,PLS SUGGEST ME I HAVE NO IDEA WHERE TO PLACE THE FUNCTIONS.PHP CODE.I HAVE WAMP SERVER .CAN I PASTE THE FUNCTIONS.PHP THERE .OR ANY OTHERWAY .HOW FLEX CONNECT WITH WAMP .IF SO PLS
steps for installing mysql using msi package
steps for installing mysql using msi package  how to install mysql using msi package   Hello Friend, MySQL is open source database. Here is the link for the page from where you can understand how to Download
JSF Tutorials: Easy steps to learn JSF
JSF Tutorials: Easy steps to learn JSF JavaServer Faces or JSF is a web application based on Java programming language used for building component-based user... is a part of Java Platform and was formalized as a standard through the Java
pls provide steps to write ejb3.0 simple application in eclipse - EJB
pls provide steps to write ejb3.0 simple application in eclipse   hi, pls provide steps to create simple ejb3.0 application in eclipse .And also how to create entity bean ,session bean in ejb3.0
pls provide steps to connect mysql database in flex - XML
pls provide steps to connect mysql database in flex  hi,i am new to flex and doing project. i have doubt in how to connect MYSQL database in flex .pls provide the steps . i would be really thankful 2 u. i am loooking
pls provide steps to connect mysql database in flex - XML
pls provide steps to connect mysql database in flex  hi, pls provide steps to connect mysql database in flex.pls i am trying from last week still it was not connected .pls provide the step by step procedure.i am looking
Advertisements
 

 

 

DMCA.com