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




Have Programming Question? Ask it here!
 
 
 


Anoop Kumar
Java Steps
1 Answer(s)      4 years and 8 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
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
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
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 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
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
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
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
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
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 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
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
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
How to get Java?
Video Tutorial - How to Get Java? This video tutorial explains you the steps needed to get the Java Development kit and install on your computer. This video... variable. It is necessary to configure the path variable before compiling the Java
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
Downloading and installing Maven 3 - Tutorial of Maven 3 explaining the steps to download and configure Maven 3
and it is configured. You can open the command prompt and then type java -version to see the version of Java installed on your computer. If it is installed then it will display the Java version. If Java is not installed and you don't know how
MYSQL Java Connector Library
Where to download the MYSQL Java Connector Library and get the jar file This article discuss 'how to connect Java and MYSQL using MYSQL connector' in Java. The article will give you view on downloading and installing MYSQL Java
Log4J Tutorials: Using Log4J in Easy Steps
Log4J Tutorials: Using Log4J in Easy Steps Log4j is a logging library for Java... Software Foundation. Log4j is one of best Java logging frameworks used... and efficient API for the Java developers allowing them to use Log4j easily
How to Get Started with Java?
steps to follow: Writing and saving Source Code with file extension .java...A Java Beginners Tutorial - How to Get Started with Java? For a programmer Java offers some challenges that are uncommon with other environments and to get
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
PHP Steps
that a PHP file embed with HTML tags and is written from the syntax of C, Java
How to Unjar a Jar file in Java
that comes with a JDK. Following are the steps to Unjar a Jar file in Java for Windows...\Java". Following these steps will help you to unjar or extract a jar file...A JAR file is a collection of Java class files that contains images, methods
Struts 2 Tutorial: Easy steps to learn Struts 2
Struts 2 Tutorial: Easy steps to learn Struts 2 Apache Struts 2 is a popular Java Model-View-Controller (MVC) framework used to build enterprise-ready Java... are Servlet API 2.4, JSP API 2.0 and Java 5. Struts 2 Tutorial at Roseindia.net
Download and Install Java
is very easy and you can follow the steps and easily install the Java on your... Download and Install Java       To compile and run a java
Core Java Hello World Example
Create Java Hello World Program This tutorial explains you how to create a simple core Java "Hello World" application. The Hello World application... explains you about all the steps in creating Hello World application
Java Method Return Multiple Values
the steps required in to return multiple values in Java. In this example you will see...Java Method Return Multiple Values In this section we will learn about how a method can return multiple values in Java. This example explains you how
Installing Java (JDK 7) on Windows 7 Computer Video Tutorial
Installing Java (JDK 7) on Windows 7 Computer Video Tutorial
java - Java Beginners
java  Can you please provide me the steps for running the Java Doc Comments with a simple program please
 

 

 

DMCA.com