Help:how to use java.util.jar to zip or unzip a binary file.

how to use java.util.jar to zip or unzip a binary file or a file contain native code.

It may help you to know how I add JARs
1. I open my Project (myProject)
2. I Mount the JAR to the FileSystem (like mypackages.jar = which includes com.mus.de.myClass.java)
3. I Mount the File to the FileSystem (like c:\..myfiles..\myProject)
3.1 I add the File to my Project
4. I select File | New -> Classes | Main
4.1 I typed "import com.mus.de.myClass.java" to refer to this package.
4.2 I called some of the public methods
thats it
Andreas

Similar Messages

  • Problem in Creating a jar file using java.util.jar and deploying in jboss 4

    Dear Techies,
    I am facing this peculiar problem. I am creating a jar file programmatically using java.util.jar api. The jar file is created but Jboss AS is unable to deploy this jar file. I have also tested that my created jar file contains the same files. When I create a jar file from the command using jar -cvf command, Jboss is able to deploy. I am sending the code , please review it and let me know the problem. I badly require your help. I am unable to proceeed in this regard. Please help me.
    package com.rrs.corona.solutionsacceleratorstudio.solutionadapter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.util.jar.JarEntry;
    import java.util.jar.JarOutputStream;
    import java.util.jar.Manifest;
    import com.rrs.corona.solutionsacceleratorstudio.SASConstants;
    * @author Piku Mishra
    public class JarCreation
         * File object
         File file;
         * JarOutputStream object to create a jar file
         JarOutputStream jarOutput ;
         * File of the generated jar file
         String jarFileName = "rrs.jar";
         *To create a Manifest.mf file
         Manifest manifest = null;
         //Attributes atr = null;
         * Default Constructor to specify the path and
         * name of the jar file
         * @param destnPath of type String denoting the path of the generated jar file
         public JarCreation(String destnPath)
         {//This constructor initializes the destination path and file name of the jar file
              try
                   manifest = new Manifest();
                   jarOutput = new JarOutputStream(new FileOutputStream(destnPath+"/"+jarFileName),manifest);
              catch(Exception e)
                   e.printStackTrace();
         public JarCreation()
         * This method is used to obtain the list of files present in a
         * directory
         * @param path of type String specifying the path of directory containing the files
         * @return the list of files from a particular directory
         public File[] getFiles(String path)
         {//This method is used to obtain the list of files in a directory
              try
                   file = new File(path);
              catch(Exception e)
                   e.printStackTrace();
              return file.listFiles();
         * This method is used to create a jar file from a directory
         * @param path of type String specifying the directory to make jar
         public void createJar(String path)
         {//This method is used to create a jar file from
              // a directory. If the directory contains several nested directory
              //it will work.
              try
                   byte[] buff = new byte[2048];
                   File[] fileList = getFiles(path);
                   for(int i=0;i<fileList.length;i++)
                        if(fileList.isDirectory())
                             createJar(fileList[i].getAbsolutePath());//Recusive method to get the files
                        else
                             FileInputStream fin = new FileInputStream(fileList[i]);
                             String temp = fileList[i].getAbsolutePath();
                             String subTemp = temp.substring(temp.indexOf("bin")+4,temp.length());
    //                         System.out.println( subTemp+":"+fin.getChannel().size());
                             jarOutput.putNextEntry(new JarEntry(subTemp));
                             int len ;
                             while((len=fin.read(buff))>0)
                                  jarOutput.write(buff,0,len);
                             fin.close();
              catch( Exception e )
                   e.printStackTrace();
         * Method used to close the object for JarOutputStream
         public void close()
         {//This method is used to close the
              //JarOutputStream
              try
                   jarOutput.flush();
                   jarOutput.close();
              catch(Exception e)
                   e.printStackTrace();
         public static void main( String[] args )
              JarCreation jarCreate = new JarCreation("destnation path where jar file will be created /");
              jarCreate.createJar("put your source directory");
              jarCreate.close();

    Hi,
    I have gone through your code and the problem is that when you create jar it takes a complete path address (which is called using getAbsolutePath ) (when you extract you see the path; C:\..\...\..\ )
    You need to truncate this complete path and take only the path address where your files are stored and the problem must be solved.

  • Modifying JAR file using java.util.jar package  over the network

    Hello,
    I am modifying a JAR file programmatically using java.util.jar package. The time taken to save the contents to a local disk is very less (around 1 sec) . When I tried modifying the JAR from a remote machine over the network (from mapped drive or shared folder of WIN NT), the time taken to save is 15-20 times more.
    I am recreating the whole JAR while modifying. Is there any way to improve the performance. Or is it possible to write only the changed files?
    Thanks,
    Prasad Y S.

    When you "update" a jar file, you must always recreate it from scratch.

  • How to use java.util.UUID in a function?

    This works:
    create or replace and compile
    java source named "RandomUUID"
    as
    public class RandomUUID
    public static String create()
    return "123";
    But this does not work:
    create or replace and compile
    java source named "RandomUUID"
    as
    public class RandomUUID
    public static String create()
    return java.util.UUID.randomUUID().toString();
    Can anybody explain?
    The log window shows the following strings:
    oracle.dbtools.worksheet.commands.scriptrunner.task.ScriptRunnerTask
    oracle.dbtools.raptor.newscriptrunner.PLSQL.reportWarning(PLSQL.java:261)
    But I have no idea what this could mean.

    This is the forum for Oracle's SQL Developer tool, not for general SQL and PL/SQL questions. Questions like this will get a better response in the PL/SQL forum, or a java forum.
    Incidentally, you need to be clearer on what "does not work" means. Does not compile? Doesn't run? Doesn't produce the expexted result.

  • How do I specify utility jars that my application needs in EAR file

    I'm using weblogic 7.0 and trying to deploy and application. I would like to add
    any utility classes related to this application with in the .ear file and deploy
    the application. Where should I add these files. Does APP-INF/lib work with 7.0?
    Please suggest some sol...
    Thanks

    You'll need to use manifest class-path entries in 7.0. It's covered in
    the J2EE spec, or if you search this newsgroup, you should see plenty of
    examples.
    -- Rob
    Jaya wrote:
    I'm using weblogic 7.0 and trying to deploy and application. I would like to add
    any utility classes related to this application with in the .ear file and deploy
    the application. Where should I add these files. Does APP-INF/lib work with 7.0?
    Please suggest some sol...
    Thanks

  • How do I estimate time takes to Zip/Unzip using java.util.zip ?

    If I am compressing files or uncompressing zips using java.util.zip is there a way for me to tell the user how long it should take or for perhaps displaying a progress monitor ?

    For unzip use the ZipInputStream and pass it a CountingInputStream that keeps track ofr the number of bytes read from it (you write this). This CountingInputStream extends fileInputStream and as such can provide you with information about the total number of bytes available to be read and the number already read. This can give a crude idea of how much work has been done and how much work still needs to be done. It is inaccurate but should be good enoough for a progress bar
    As for zipping use the ZipOutputStream and pass it blocks of information. Keep track of the number of blocks you have written and the number you still need to write.
    matfud

  • How can I use java.util.Date and change display format.

    Hello All,
    I want to use java.util.Date in View Context and in Custom Control Context of Web dynpro java. When i mapped of a Input Field to the java.util.Date then message shows that its not supported. Plz suggest me how to handle Date with different formats ??

    If you always want the user to enter the date in dd/MM/yyyy, you can do the following.
    Goto Local Dictonary -> Simple types in your project and create a type known as "InputDate" (or whatever you feel) of built-in type 'Date'.
    Now specifiy its format in the 'Representation' tab as "dd/MM/yyyy" (case-senstive).
    Now declare a value attribute say "inputdate" in your context with this type and bind the inputfield to this context value attribute.
    This will solve your problem.
    But if you want the user to input date depending on the region he belongs, change the default locale date in Control Panel->Regional and Language Options->Change to English(UK) -> Customize -> Date Tab -> Sort Date Format to dd/MM/yyyy.
    Now clear the cache, delete temporary files and restart the machine. This should solve the problem.

  • JNI - how to use java access function in TypeLibrary( .tlb file) HELP ME PL

    Hey All
    I got one project which can be done by calling up functions in xxxx.tlb
    (window type library) file, that is no problem.
    How to use java to access those functions???
    I know there are some classes which can be used to access function in
    DLL file e.g. JAWIN.
    Is the .tlb file related to one DLL file??? if so, how to locate the
    DLL file through .tlb file???
    Thanks a lot.
    Steve

    Use JNI to create a link between Java class and a DLL, then you can load that DLL (or TLB) from that class.
    Read the JNI Tutorials.

  • How to use java source in Oracle when select by sqlplus.

    How to use java source in Oracle when select by sqlplus.
    I can create java source in Oracle
    import java.util.*;
    import java.sql.*;
    import java.util.Date;
    public class TimeDate
         public static void main(String[] args)
    public String setDate(int i){
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(new Date((long)i*1000));
    System.out.println("Dateline: "
    + calendar.get(Calendar.HOUR_OF_DAY) + ":"
    + calendar.get(Calendar.MINUTE) + ":"
    + calendar.get(Calendar.SECOND) + "-"
    + calendar.get(Calendar.YEAR) + "/"
    + (calendar.get(Calendar.MONTH) + 1) + "/"
    + calendar.get(Calendar.DATE));
    String n = calendar.get(Calendar.YEAR) + "/" + (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.DATE);
         System.out.print(n);
         return n;
    I have table name TEST
    ID DATE_IN
    1 942685200
    2 952448400
    When I write jsp I use method setDate in class TimeDate
    The result is
    ID DATE_IN
    1 1999/11/16
    2 2003/7/25
    Thanks you very much.

    It is unclear where you are having a problem.  Is your issue at runtime (when the form runs in the browser) or when working in the Builder on the form?
    Also be aware that you will need to sign your jar and include some new manifest entries.  Refer to the Java 7u51 documentation and blogs that discuss the changes.
    https://blogs.oracle.com/java-platform-group/entry/new_security_requirements_for_rias
    http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/manifest.html

  • How to prevent java.util.logging from displaying pop-up dialog on SEVERE?

    Hi,
    I'm new to using java.util.logging. I notice that whenever I try to make a call to logger.SEVERE(msg) or logger.WARNING(msg), not only does it write the output to file (which I want), but it also pops up a dialog box displaying the exception. I don't want this pop up to appear. How do I prevent the logger from doing this?

    What are you talking about?
    Hello,
    In order to better assist you with your issue please provide us with a screenshot. If you need help to create a screenshot, please see [[How do I create a screenshot of my problem?]]
    Once you've done this, attach the saved screenshot file to your forum post by clicking the '''Browse...''' button below the ''Post your reply'' box. This will help us to visualize the problem.
    Thank you!

  • Java.util.zip java.util.jar API usage

    I have been trying unsuccessfully for the past two days to be able to programatically add and extract files into and from a JAR using the API. I haven't found any API docs that cover the basics and I have been stumped using the nuggets that I have found on the Forum so far. Below is the code so far. Feel free to use what works in your programs, but if you find out how to get this to work. Sorry for the long post, but I gather this is a common problem that needs to be solved.
    ___________JAR CLASS_______________
    import java.io.*;
    import java.util.*;
    import java.util.jar.*;
    import java.util.zip.*;
    public class Jar {
        public Jar() {
        public boolean copyToJar(File[] sources, File destination) {
            if (destination == null) {
                return false;
            if (nameContainsWildcards(destination)) {
                return false;
            File[] sourceArray = expandWildcards(sources);
            if (sourceArray == null) {
                System.out.println("sourceArray was empty");
                return false;
              System.out.println("Ready to add " + sourceArray.length + " files to " + destination);
              //variables for copying the old destination file to the new destination
              File tmpFile = null;
              JarFile tmpJarFile = null;
              InputStream jarInput = null;
              JarInputStream jarIn = null;
            InputStreamReader jarDataFile = null;
              //variables for the destination
            OutputStream output = null;
            JarOutputStream jarOut = null;
            File input = null;
            FileInputStream dataFile = null;
            int buf = -1;
              if (destination.exists()) {
                   System.out.println("The destination file exists");
                   //copy the destination to temporary
                   //fix copyToJar to use the same .tmp file name as the destination (for reentrant code)
                   tmpFile = new File(destination.getParent() + "\\" + "jar.tmp");
                   if (tmpFile.exists()) {
                        tmpFile.delete();
                   //rename the original to the TempFile
                   destination.renameTo(tmpFile);
                   if (destination.exists()) {
                        destination.delete();
                   try {
                        tmpJarFile = new JarFile(tmpFile);
                   } catch (IOException ioe) {
                        System.out.println("Exception while creating JarFile " + ioe );
            try {
                   //initialize the destination
                output = new FileOutputStream(destination);
                jarOut = new JarOutputStream(output);
                   //if there is a tmpFile copy contents of tmpFile to the new destination
                   if (tmpFile != null) {
                        jarInput = new FileInputStream(tmpFile);
                        jarIn = new JarInputStream(jarInput);
                        ZipEntry ze = null;
                        boolean contains = false;
                        while((ze = jarIn.getNextEntry()) != null) {
                             System.out.println("Working on zipEntry " + ze.getName());
                             contains = false;
                             for (int i=0; i<sourceArray.length; i++) {
                                  if (ze.getName().compareToIgnoreCase(sourceArray.getName()) == 0) {
                                       contains = true;
                             if (contains == false) {
              jarDataFile = new InputStreamReader(tmpJarFile.getInputStream(ze));
                                  System.out.println("The zip Entry was copied from the old file");
                                  jarOut.putNextEntry(ze);
                                  buf = -1;
                                  buf = jarDataFile.read();
                                  while (buf != -1) {
                                       jarOut.write(buf);
                                       buf = jarDataFile.read();
                                  jarOut.closeEntry();
                                  jarDataFile.close();
                        jarIn.close();
                        jarInput.close();
                        tmpFile.delete();
                        tmpJarFile.close();
                   //copy the new files to the destination
    for (int i=0; i<sourceArray.length; i++) {
    if (sourceArray[i].isDirectory()) {
                             //fix copyToJar to copy entire directory if the directory is given as a source
    } else {
    System.out.println("Adding " + sourceArray[i].getAbsolutePath() + " to "
    + destination.getAbsolutePath());
    dataFile = new FileInputStream(sourceArray[i]);
    ZipEntry entry= new ZipEntry(sourceArray[i].getName());
    jarOut.putNextEntry(entry);
    buf = -1;
    buf = dataFile.read();
    while (buf != -1) {
    jarOut.write(buf);
    buf = dataFile.read();
    jarOut.closeEntry();
    jarOut.close();
    output.close();
    dataFile.close();
    } catch (IOException ioe) {
    System.out.println("Exception " + ioe + " occured while writing the backup jar file.");
    try {
    if (jarOut != null)
    jarOut.close();
    if (output != null)
    output.close();
    if (dataFile != null)
    dataFile.close();
    if (jarInput != null)
    jarInput.close();
    if (jarIn != null)
    jarIn.close();
    } catch (IOException ioe2) {
    System.out.println("Exception " + ioe2 + " closing the jar file.");
    return false;
    return true;
    public boolean copyToJar(File source, File destination) {
    File[] sourceArray = expandWildcards(source);
    if (sourceArray == null) {
    System.out.println("sourceArray was empty");
    return false;
    return copyToJar(sourceArray, destination);
         public boolean extractFromJar(File source, File extract, File destDirectory) {
              try {
                   JarFile jarIn = new JarFile(source);
                   ZipEntry ze = jarIn.getEntry(extract.getName());
                   if (ze == null) {
                        System.out.println("Could not find file " + extract + " in jarFile " + source);
                   } else {
                        JarInputStream jarInput = null;
                        InputStreamReader buf = null;
                        FileOutputStream out = null;
                        InputStream in = jarIn.getInputStream(ze);
                        buf = new InputStreamReader(in);
                        out = new FileOutputStream(extract);
                        int buffer = -1;
                        buffer = buf.read();
                        while (buffer != -1) {
                             out.write(buffer);
                             buffer = buf.read();
              } catch (IOException ioe) {
                   System.out.println("Could not extract the file " + extract + " from jarFile " + source);
                   return false;
              return true;
    public int numberOfLines(File fileToCount) {
    int num = 0;
    try {
    FileReader regRead = new FileReader(fileToCount);
    LineNumberReader regReadLine = new LineNumberReader(regRead);
    while (regReadLine.readLine() != null) {
    num = regReadLine.getLineNumber();
    regRead.close();
    regReadLine.close();
    } catch (IOException ioe) {
    System.out.println("Exception " + ioe + " occured in " + this.getClass().getName());
    return num;
    static public boolean nameContainsWildcards(File source) {
    if (source != null) {
    if ((source.getName().indexOf('*')) >=0) {
    return true;
    //fix this check to look for other wildcards
    return false;
    * Expands the * wildcard that does not start the expression. For example,
    * in a directory whose contents are TEST1.DAT, TEST2.DAT AND TEST3.DAT, this
    * funtion will return the following based on the input
    * Input Returns
    * TEST1.DAT File[] containing the first file
    * TEST*.DAT File[] containing all three files plus any that match TEST*.*
    * T*.* File[] containing all three files plus any that match T*.*
    * *.* File[] containing all three files plus any that match *.*
    * EST.DAT File[] containing no files (not a legal expression...yet)
    * ? or
    public File[] expandWildcards(File source) {
    if (source == null) {
    System.out.println("Cannot expand wildCards for a null File");
    return null;
    File[] sourceArray = null;
    if (nameContainsWildcards(source)) {
    FileFilter wildcardFilter = new WildcardFilter(source.getName());
    File sourceParent = new File(source.getParent());
    if (sourceParent != null) {
    sourceArray = sourceParent.listFiles(wildcardFilter);
    } else {
    sourceArray = new File[1];
    sourceArray[0] = source;
    } else {
    sourceArray = new File[1];
    sourceArray[0] = source;
    return sourceArray;
    public File[] expandWildcards(File[] sources) {
    File[] sourceArray = null;
    List fileArrays = new ArrayList();
    for (int i=0; i< sources.length; i++) {
    fileArrays.add(expandWildcards(sources[i]));
    int totalFiles = 0;
    for (int i=0; i < fileArrays.size(); i++) {
    File[] tmp = (File []) fileArrays.get(i);
    if (tmp != null) {
         //System.out.println("Adding " + tmp.length + " to total files");
         totalFiles += tmp.length;
    System.out.println("totalFiles expanded = " + totalFiles);
    sourceArray = new File[totalFiles];
    int nextIndex = 0;
    for (int i=0; i < fileArrays.size(); i++) {
    File[] tmp = (File []) fileArrays.get(i);
    if (tmp != null) {
                        for(int j=0; j < tmp.length; j++) {
                             //System.out.println("Adding file " + tmp[j] + " to sourceArray");
                             sourceArray[nextIndex] = tmp[j];
                             nextIndex++;
    return sourceArray;
    static public void main(String argv[]) {
    Jar jarRun = new Jar();
    File testFile = new File("D:\\test.jar");
              File testFile1 = new File("C:\\Program Files\\RBusinessSystems\\Location Sync\\LONGMONT\\LongmontDefaultCustomers.jar");
              File testFile2 = new File("C:\\Program Files\\RBusinessSystems\\Location Sync\\LONGMONT\\LongmontDefaultInventory.jar");
              File testFile3 = new File("C:\\Program Files\\RBusinessSystems\\Location Sync\\LONGMONT\\LongmontDefaultVendors.jar");
              File testFile4 = new File("C:\\Program Files\\RBusinessSystems\\Location Sync\\LONGMONT\\LongmontDefaultClerks.jar");
              if (argv.length >= 1) {
                   System.out.println("Creating the Jar File");
                   jarRun.copyToJar(testFile1, testFile);
                   jarRun.copyToJar(testFile2, testFile);
                   jarRun.copyToJar(testFile3, testFile);
                   jarRun.copyToJar(testFile4, testFile);
              } else {
                   System.out.println("Extracting from the Jar File");
                   jarRun.extractFromJar(testFile, new File("d:\\LongmontDefaultCustomers.jar"), new File("d:\\"));
                   jarRun.extractFromJar(testFile, new File("d:\\LongmontDefaultInventory.jar"), new File("d:\\"));
                   jarRun.extractFromJar(testFile, new File("d:\\LongmontDefaultVendors.jar"), new File("d:\\"));
                   jarRun.extractFromJar(testFile, new File("d:\\LongmontDefaultClerks.jar"), new File("d:\\"));
    ______________WILDCARD FILTER CLASS __________
    import java.io.File;
    import java.io.FileFilter;
    public class WildcardFilter implements FileFilter {
        private String compare = null;
        private String wildcardStart = null;
        private String wildcardMiddle = null;
        private String wildcardEnd = null;
        WildcardFilter(String comparison) {
            setCompare(comparison);
        public void setCompare(String comparison) {
            compare = comparison.toLowerCase();
            wildcardStart = null;
            wildcardMiddle = null;
            wildcardEnd = null;
            int index = compare.indexOf('*');
            if (index != -1) {
                wildcardStart = compare.substring(0, index);
                if (index + 1 < compare.length()) {
                    wildcardEnd = compare.substring(index + 1, compare.length());
                System.out.println("Expanding fileNames starting with " + wildcardStart
                          + " and ending with " + wildcardEnd);
        public boolean accept(File check) {
            String checkName = check.getName().toLowerCase();
            if (compare == null) {
                return false;
            if (((wildcardEnd == null) || (wildcardEnd.compareTo("") == 0))
                && ((wildcardStart == null) || (wildcardStart.compareTo("") ==0))) {
                return false;
            if (((wildcardStart == null) || (wildcardStart.compareTo("") ==0))
                && (wildcardEnd != null)) {
                if ((wildcardEnd.compareTo(".*") ==0) || (wildcardEnd.compareTo("*") == 0))
                    return true;
                if (checkName.endsWith(wildcardEnd))
                    return true;
            if (((wildcardEnd == null) || (wildcardEnd.compareTo("") == 0))
                && (wildcardStart != null)) {
                if (checkName.startsWith(wildcardStart))
                    return true;
            if ((checkName.startsWith(wildcardStart))
                && (checkName.endsWith(wildcardEnd))) {
                return true;
            return false;

    I figured it out based on some of the other posts I found on this Forum. Following is the working code. While this code is not as robust as it needs to be for production, it will at least get you started on extracting from jar files and writing to jarfiles.
    import java.io.*;
    import java.util.jar.*;
    import java.util.zip.*;
    //NOTE: You can only copy entries created by the Jar tool
    class JarTest {
        JarTest() {
        public boolean copyToJar(File[] fileList, File jarFile) {
            JarEntry je = null;
            File tmpFile = null;
            FileOutputStream fos = null;
            JarOutputStream jos = null;
            BufferedWriter bw = null;
            FileInputStream fis = null;
            JarInputStream jis = null;
            BufferedReader br = null;
            int buf = -1;
            boolean badZipFile = false;
            boolean refreshFromNewFile = false;
            String tmpFileName = jarFile.getAbsolutePath() + ".tmp";
            try {
                tmpFile = new File(tmpFileName);
                fos = new FileOutputStream(tmpFile);
                jos = new JarOutputStream(fos);
                bw = new BufferedWriter(new OutputStreamWriter(jos));
            } catch (IOException ioe) {
                ioe.printStackTrace();
        if(jarFile.exists()) {
                try {
                    fis = new FileInputStream(jarFile);
                    jis = new JarInputStream(fis);
                    br = new BufferedReader(new InputStreamReader(jis));
                } catch (IOException ioe) {
                    System.out.println(ioe);
                try {
                    while((je = jis.getNextJarEntry()) != null) {
                        refreshFromNewFile = false;
                        for (int i = 0; i < fileList.length; i++) {
                            if (je.getName().compareToIgnoreCase(fileList.getName()) == 0) {
    refreshFromNewFile = true;
    if (refreshFromNewFile) {
    //do nothing so we can add the new file below
    } else {
    jos.putNextEntry(je);
    int index = 0;
    buf = -1;
    while((buf = br.read()) != -1) {
    bw.write(buf);
    index++;
    System.out.println("Copied entry " + je.getName() + " of " + index + " bytes from " + jarFile.getName());
    bw.flush();
    jos.closeEntry();
    } catch (IOException ioe) {
    ioe.printStackTrace();
    badZipFile = true;
    try {
    br.close();
    jis.close();
    fis.close();
    } catch (IOException ioe) {
    ioe.printStackTrace();
    for (int i = 0; i < fileList.length; i++) {
    try {
    fis = new FileInputStream(fileList[i]);
    br = new BufferedReader(new InputStreamReader(fis));
    // write the new entries to the tmpFile
    je = new JarEntry(fileList[i].getName());
    jos.putNextEntry(je);
    int index = 0;
    buf = -1;
    while((buf = br.read()) != -1) {
    bw.write(buf);
    index++;
    bw.flush();
    System.out.println("Added entry " + je.getName() + " of " + index + " bytes.");
    jos.closeEntry();
    } catch (IOException ioe) {
    ioe.printStackTrace();
    badZipFile = true;
    try {
    jos.close();
    if (tmpFile != null) {
    // rename the tmpFile to jarFile
    jarFile.delete();
    tmpFile.renameTo(jarFile);
    } catch (IOException ioe) {
    ioe.printStackTrace();
    return true;
    public boolean extractFromJar(File[] fileList, File jarFile) {
    ZipEntry zen = null;
    BufferedReader br = null;
    FileOutputStream fos = null;
    BufferedWriter bw = null;
    try {
    for (int i = 0; i < fileList.length; i++) {
    JarFile jar = new JarFile(jarFile);
    zen = jar.getEntry(fileList[i].getName());
    if (zen == null) {
    System.out.println("Could not find the file " + fileList[i].getName() + " in the zip file " + jar.getName());
    } else {
    File parentDirectory = new File(fileList[i].getParent());
    parentDirectory.mkdirs();
    InputStream in = jar.getInputStream(zen);
    br = new BufferedReader(new InputStreamReader(in));
    fos = new FileOutputStream(fileList[i]);
    bw = new BufferedWriter(new OutputStreamWriter(fos));
    int buf = -1;
    int index = 0;
    while((buf = br.read()) != -1) {
    bw.write(buf);
    bw.flush();
    index++;
    System.out.println("Extracted file " + fileList[i] + " of " + index + " bytes from " + jarFile);
    br.close();
    bw.close();
    } catch (IOException ioe) {
    System.out.println(ioe);
    return false;
    return true;
    public static void main(String[] argv) {
    JarTest jt = new JarTest();
    File jarFile = new File("d:\\test\\test.zip");
    File[] fileList1 = new File[] {new File("d:\\test\\CustomerRefreshRequest.bat"),
                                            new File("d:\\test\\CustomerUpdateGet.bat"),
                                            new File("d:\\test\\CustomerUpdateRequest.bat"),
                                            new File("d:\\test\\LongmontDefaultClerks.jar"),
                                            new File("d:\\test\\LongmontDefaultCustomers.jar"),
                                            new File("d:\\test\\LongmontDefaultInventory.jar")};
    File[] fileList2 = new File[] { new File("d:\\test\\install.bat"),
    new File("d:\\test\\LongmontDefaultVendors.jar"),
    new File("d:\\test\\CustomerUpdateSend.bat") };
    jt.copyToJar(fileList1, jarFile);
    jt.copyToJar(fileList2, jarFile);
    File[] fileList3 = new File[] {new File("d:\\test\\temp\\CustomerRefreshRequest.bat"),
                                            new File("d:\\test\\temp\\CustomerUpdateGet.bat"),
                                            new File("d:\\test\\temp\\CustomerUpdateRequest.bat"),
                                            new File("d:\\test\\temp\\LongmontDefaultClerks.jar"),
                                            new File("d:\\test\\temp\\LongmontDefaultCustomers.jar"),
                                            new File("d:\\test\\temp\\LongmontDefaultInventory.jar")};
    File[] fileList4 = new File[] { new File("d:\\test\\temp\\INSTALL.BAT"),
    new File("d:\\test\\temp\\LongmontDefaultVendors.jar"),
    new File("d:\\test\\temp\\CustomerUpdateSend.bat") };
    jt.extractFromJar(fileList3, jarFile);
    jt.extractFromJar(fileList4, jarFile);

  • How TO Use Java Mapping In XI

    Hi Experts,
    please help me ,
    How TO Use Java Mapping In XI?
    Thanks
    Mahesh

    Hi,
    Just refer the following links for java mapping:-
    1./people/thorsten.nordholmsbirk/blog/2006/08/10/using-jaxp-to-both-parse-and-emit-xml-in-xi-java-mapping-programs
    2./people/alessandro.guarneri/blog/2007/03/25/xi-java-mapping-helper-dom
    Regards,
    Ashwin M
    Reward if helpful

  • How to use java integrate with ondemand

    Hi All,
    As i'm new to integration, can anyone help me to use java integrate with ondemand that inserts some records in ondemand and deletes some records from ondemand in secheduled interval basis.?
    Thanks in advance..!
    regards
    sowm

    Greetings,
    hi forum...
    how to use Java WebStart with EJB ? examples ?Well, for starters these are complementing, not 'cooperating', technologies. I presume, since EJB's do not - directly, at least - communicate with a web browser, that you intend for "Java WebStart" to somehow invoke an EJB?? Java WebStart is a technology for running client-side (Java) applications from the web browser - perceptively, the application resides on the server, but technically it, like an applet, is downloaded to the client and run there. Unlike an applet, however, it is not constrained by "sandbox" restrictions and does not have to be re-downloaded each time it is invoked - though the process allows for automagically updating the client-side with new versions of the application. ;) So, with this in mind, to "use Java WebStart with EJB" means little more than deploying an EJB client application with Java WebStart as the distribution channel.
    thanks
    minduRegards,
    Tony "Vee Schade" Cook

  • How to use java in Form 9i

    hi
    i want to ask how to use java in form 9i, can any one plz. give me an example
    thanks & best regards!
    SoftDesire

    From an earlier posting:
    "Have a look in the online help for "Java Importer", PJC and "Java Bean".
    There are also some paper on otn.oracle.com/products/forms
    Click to view the papers and you will see a couple which should how to integrate Forms and Java.
    Hope this helps.
    Grant Ronald
    Forms Product Management"
    HOpe this helps.
    Grant

  • How to use java 6 and uninstall java 7 ?

    Curently I'm facing some problem uninstall java 7, whenever I delete java 7 and install java 6,  when i check on my java -version it is showing java version "1.7.0_09".
    How can use java 1.6 instead of 1.7 ? Please help thanks.

    The following article should show you how:
       https://service.parachat.com/knowledgebase/226/How-can-I-uninstall-Oracle-Java-7 -and-reinstall-Apples-Java-6-on-my-Mac.html
    Hope this helps

Maybe you are looking for