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

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 Pages:
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
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
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
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
PHP Steps
that a PHP file embed with HTML tags and is written from the syntax of C, Java
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
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
Steps for the payment gateway processing?
Steps for the payment gateway processing?  Steps for the payment gateway processing
what are the steps in jdbc?
what are the steps in jdbc?  what are the steps in jdbc
Steps to create simple EJb 2.1 (Session Bean) and deploy on websphere application server 6.0,
Steps to create simple EJb 2.1 (Session Bean) and deploy on websphere... session bean having Java client. but i am unable to run it on Websphere application server. can any one please send me steps how i create EJB 2.1 and deploy
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 log4j configuration in Struts2
Steps to log4j configuration in Struts2  Hi... any tel me each step for configure log4j in struts2 application
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 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
Java review
Object-Oriented Programming Graphical User Interface Components I Typical Java Compilation/Execution Steps Edit source (.java) program (eg, your IDE) Compile... Java review Organized by Java: How to Program chapter. About Java
JButton
Java: JButton Description There are a few steps in using a button: declaring it, creating it, adding it to a container (the content pane or a JPanel), and adding a listener that has code to execute when the user clicks
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 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
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
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
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
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
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
Compiling a Java program
Java NotesCompiling a Java program Turning a Java source program into an object program takes a couple of steps. Assuming that you are using the popular, but awkward, JDK (Java Development Kit) by Sun Microsystems, do the following
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
How to Program in Java
to write Java program. Here are the steps of programming Java: Step 1: Download...This tutorial tells you how to program in Java? As a beginner you must know how to start programming in Java. Java is programming language which can be used
INTRODUCING JAVA SERVER FACES (JSF)
of the tutorial, the author explains the practical steps to get our first few demos in JSF, running. Basic theory behind the steps also are given. We are using Tomcat-5.... ----------------------------   >e:\tomcat5\bin   >set JAVA_HOME=e:\jdk1.4.2  
Creating files in jpa project
, you need to follow the following steps: Right click on "Source... => Java Package... Give the package name "roseindia"
Creating a Project
; This section explains the steps involved in developing a project in Eclipse IDE. These steps are: 1. Now, go and click to file->new->project icon.Click on ?Java Project? and give a project name of your choice (?NewProject
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers  how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
Java File Download Example
Java File Download Example To make an application that downloads the file from the remote locations, you might used to follow the steps as given below, 1... you have to download as, URL url = new URL("http://www.roseindia.net/java
java
java  how to open and run an existing eclipse project in eclipse-SDK-3.4.2-win32.. Pls help me out with proper procedure and steps.. Thank yo
hi .. need help ASAP ..i have a project buit in eclipse , i have installed jasper. i want the steps to work on it ..
hi .. need help ASAP ..i have a project buit in eclipse , i have installed jasper. i want the steps to work on it ..   hi .. need help ASAP ..i have a project buit in eclipse , i have installed jasper. i want the steps to work
JSF Interview Questions
? The series of steps followed by an application is called its life cycle. A JSF application typically follows six steps in its life... the component data from String to Java objects and vice versa. For example
DEVELOPING & DEPLOYING A PACKAGED EJB
' is very important in Enterprise Java. Compiling and Deploying such packaged servlets & EJB, requires careful steps. In this tutorial, the author explains.... Otherwise, there will be name-collision. Java language provides a built
java
java  in my project i need to add a print button to JSP page. On clicking it the the current JSP page have to printed. how to implement it.. Pls provide me steps.. Thank yo
java
java  in my project i need to add a print button to JSP page. On clicking it the the current JSP page have to printed. how to implement it.. Pls provide me steps.. Thank yo
Installing JSF 1.1 in TOMCAT 5.5.23
installation of JSF 1.1 to TOMCAT 5.5.23. Java Server Faces (JSF) requires some steps to follow while configuring it in TOMCAT. Here we are considering you... Tomcat 5.5.23 Jsf 1.1 Servlet 2.3 Jsp 1.2  The steps required
java - Java Beginners
java  Can you please provide me the steps for running the Java Doc Comments with a simple program please
Download and Install Java
Download and Install Java       To compile and run a java program we need to install java platform. JDK (Java Development Kit). JDK
WoLips Plugin
for WebObjects development. The easiest way to install WOLips is to follow the steps.... WOProject-Ant : provides a way to build WebObjects applications and standalone Java... applications and standalone Java launchers with Maven. For more
How to Create Excel Page Using JSP
using java .By going through the steps of  this example we can create any.... This API is  provided by the Apache Jakarta (Jakarta POI - Java API To Access... using pure word files using Java. We can create, read or write MS Excel file using
java - Struts
Java long to string conversion  What is the steps to convert a long to String in Java

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.