Problem in deleting Zip files unzipped using java.util.zip

I have a static methos for unzipping a zip file. after unzipping the file when i am trying to delete that file using File.delete()its not getting deleted. but when methods like exist(). canRead(), canWrite() methods are returning true what can be the possible problem ? i had closed all the streams after unzipping operation Please go through the following code.
public static boolean unzipZipFile(String dir_name, String zipFileName) {
try {
ZipFile zip = new ZipFile(zipFileName);
Enumeration entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
// got all the zip entries here
// now has to process all the files
// first all directories
// then all the files
if (entry.isDirectory()) {
// now the directories are created
File buf=new File(dir_name,entry.getName());
buf.mkdirs();
continue;
}// now got the dirs so process the files
entries = zip.entries();
while(entries.hasMoreElements()) {
// now to process the files
ZipEntry entry = (ZipEntry) entries.nextElement();
if (!entry.isDirectory()){
File buf=new File(dir_name,entry.getName());
copyInputStream(
zip.getInputStream(entry),
new BufferedOutputStream(
new FileOutputStream(buf)));}
} catch (IOException e) {
e.printStackTrace();
return false;
return true;
now i am trying to call this method to unzip a zip file
public static void main (String arg[]){
unzipZipFile("C:/temp","C:/tmp.zip");
java.io.File filer = new File("C:/tmp.zip");
System.out.println (filer.canRead());
System.out.println (filer.canWrite());
System.out.println (filer.delete());
Please tell me where my program is going wrong ?

Thanks .. the problem is solved... i was not closing the Zip file .. rather i was trying to close all the other streams that i used for IO operaion ... thanks a lot

Similar Messages

  • 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

  • Using java.util.zip.ZipFile

    I have files that are about 4GB (with possible growth in the future) that will be sent to a file system and a java process will be used to unzip them.
    Is there a size limit for unzipping files using java.util.zip.ZipFile?
    annie

    Chicon wrote:
    Hi annie613,
    Indeed, there's a size limit of 2GB for unzipping files, more precisely when the size of the inflated file reaches 2GB !
    Edit : inflated instead of deflated
    Edited by: Chicon on Jun 29, 2009 3:56 PMHmm, this blog says that the current limit of 4GB has been expanded by implementing ZIP64 support in OpenJDK7 build(b55).
    [http://blogs.sun.com/xuemingshen/entry/zip64_support_for_4g_zipfile]

  • Unzipping gives java.util.zip.ZipException: invalid stored block lengths

    When i try to unzip a file using java.util.zip i get the following exception
    java.util.zip.ZipException: invalid stored block lengths
    Can anyone offer any suggestions as to why this is happening?

    GZIPInputStream use mark(), reset()...
    So the InputStream you use in the constructor of GZIPInputStream must be able to handle these method.
    The simple way to achieve this is:
    new GZIPInputStream(new BufferedInputStream(yourInputStream));

  • Zipping files in a folder using java.util.zip

    hi guys,
    does any body has the java code for
    zipping files in a folder
    hi guys,
    actually i want to zip no of files in a folder .the folder can also have sub folder
    and after zipping when i extract the files manually i should
    maintain the same folder structure
    does any body has the code
    please reply me soon its a bit urgent

    hi smeee
    i tried running ur code but its not working
    here the command
    java c:\abc\ zzz.zip
    its saying
    no files or directories even though there's the
    directory present
    what's the solution Hi,
    Oops that was because of the error check added at the last moment..
    Anyway, You need to use the following command to run it :
    java ZipUtility c:\abc c:\zzz.zip
    Please use the following corrected code:
         Class to zip file(s).
         Requires jdk1.3.1.
         To run use the following command:
         java ZipUtility <directory or file to be zipped> <name of zip file to be created>
         Please specify absolute path names as its parameters while running this program.
    import java.util.zip.*;
    import java.io.*;
    public class ZipUtility {
         ZipOutputStream cpZipOutputStream = null;
         String strSource = "";
         String strTarget = "";
         String strSubstring = "";
         public static void main(String args[]) {
              if(     args == null || args.length < 2) {
                   System.out.println("Usage: java ZipUtility <directory or file to be zipped> <name of zip file to be created>");
                   return;
              ZipUtility udZipUtility = new ZipUtility();
              udZipUtility.strSource = args[0];
              udZipUtility.strTarget = args[1];
              udZipUtility.zip();
         private void zip(){
                        try
                             File cpFile = new File (strSource);
                             if (!cpFile.isFile() && !cpFile.isDirectory() ) {
                                  System.out.println("\nSource file/directory Not Found!");
                                  return;
                             if  (cpFile.isDirectory()) {
                                  strSubstring = strSource;;
                             } else {
                                  strSubstring = "";
                             cpZipOutputStream = new ZipOutputStream(new FileOutputStream(strTarget));
                             cpZipOutputStream.setLevel(9);
                             zipFiles( cpFile);
                             cpZipOutputStream.finish();
                             cpZipOutputStream.close();
                             System.out.println("\n Finished creating zip file " + strTarget + " from source " + strSource);
                        }catch (Exception e){
                             e.printStackTrace();
         private void  zipFiles(File cpFile) {
                   if (cpFile.isDirectory()) {
                        File [] fList = cpFile.listFiles() ;
                        for (int i=0; i< fList.length; i++){
                             zipFiles(fList) ;
                   } else {
                        try {
                             String strAbsPath = cpFile.getAbsolutePath();
                             String strZipEntryName ="";
                             if (!strSubstring.equals("") ){
                                  strZipEntryName = strAbsPath.substring(strSource.length()+1, strAbsPath.length());
                             } else {
                                  strZipEntryName = cpFile.getName();
                             byte[] b = new byte[ (int)(cpFile.length()) ];
                             FileInputStream cpFileInputStream = new FileInputStream (cpFile) ;
                             int i = cpFileInputStream.read(b, 0, (int)cpFile.length());
                             ZipEntry cpZipEntry = new ZipEntry(strZipEntryName);
                             cpZipOutputStream.putNextEntry(cpZipEntry );
                             cpZipOutputStream.write(b, 0, (int)cpFile.length());
                             cpZipOutputStream.closeEntry() ;
                        } catch (Exception e) {
                             e.printStackTrace();

  • Problem in clustering in Weblogic 5.1 (java.util.zip.ZipException)

    Hi All,
    We are using WLS 5.1 clustering. 2 WLS are running in 2 different unix box in same subnet. But we are getting the following exception ( Though all the Beans have been deployed successfully).
    java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.open(Compiled Code)
    at java.util.zip.ZipFile.<init>(Compiled Code)
    at java.util.zip.ZipFile.<init>(Compiled Code)
    at weblogic.boot.ServerClassLoader.deploy(ServerClassLoader.java:132)
    at weblogic.cluster.AnnotatedServiceOffer.expandClassPath(Compiled Code)
    at weblogic.cluster.AnnotatedServiceOffer.readObject(Compiled Code)
    at weblogic.common.internal.WLObjectInputStreamBase.readPublicSerializable(Compiled Code)
    Fri Jan 25 16:57:22 MST 2002:<E> <MulticastSocket> Multicast socket receive error: java.lang.RuntimeException: I/O error opening JAR file from file:/opt/wlogic/weblogic/obscluster/server113/tmp_deployments/ejbjar-4247.jar
    (cluster name we have changed to obscluster )
    This Exception is coming in both the servers The difference is that the server whose ip ends with 112 is trying to open the file from server113 dir and the server whose ip ends with 113 is trying to open the file from server112 dir.
    In web I have found that if the directory structure of 2 servers doesn't match then this porblem can arise. But for both of my servers the directory structure is same , at least until /opt/wlogic/weblogic/obscluster/ and then the directory server113 or server112 is created by Weblogic automatically when I have started the Server.
    Any help regarding this will be very helpful.
    Thanks & Regards
    Srijeeb.

    Hi everyone,
    I think I have got the solution. Using sp11. added sp11 related jar in PRE_CLASSPATH . Problem Solved....
    Thanks
    Srijeeb

  • Unzipping files using java.util

    I am trying to unzip files using java.util.zip
    It works fine when I am trying to unzip a file that is already residing on the server.
    But I want to unzip the file that user will upload to the server .
    My code is uploading zip file to server but not able to unzip this zip file giving error
    java.util.zip.ZipException: error in opening zip file
    What could be the problem
    I am not getting exactly
    Can you give me any clue
    Thanks

    sounds like the uploading is the problem. Are you FTPing the file? If so check that it's being transferred in binary, not ascii.

  • Cannot use winzip to unzip the zip file zipped by java.util.zip

    Hi all,
    I use the followcode to create a zip file, and i downlaod it and try to use winzip to unzip this file but fail. The path is correct and i got the zip file. but it just cannot unzip.
    pls help
    thanks alot.
    Kin
              int count = 0;
              count = ContentDocuments.size();
              for (int i = 0; i < bb; i++)     {
                   System.out.println(filenames[i] + "");
              // Create a buffer for reading the files
              byte[] buf = new byte[10*1024*1024];
              try {      
                   String outFilename = MyDir + "zipfile/" + getContentID2()+".zip";
                   System.out.println("outFilename = " + outFilename);
                   ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
                   for (int i=0; i<filenames.length; i++) {           
                        FileInputStream in = new FileInputStream(filenames);
                        out.putNextEntry(new ZipEntry(filenames[i]));
                        int len;
                        while ((len = in.read(buf)) != -1) {               
                             out.write(buf, 0, len);
                        out.closeEntry();
                        in.close();
                   out.close();
              } catch (IOException e)     {
                   System.err.println("zipprocess " + e.getMessage());

    I've written a replacement zip file creator class. Not much tested but it seems to work, however I've yet to try it with the version of WINZIP that rejected my previous attempts. Oh, and the stored dates are garbage.
    * ZipOutputFile.java
    * Created on 25 March 2004, 13:08
    package zip;
    import java.io.IOException;
    import java.nio.ByteBuffer;
    * <p>Creates a ZIP archive in a file which WINZIP should be able to read.</p>
    * <p>Unfortunately zip archives generated by the standard Java class
    * {@link java.util.zip.ZipOutputStream}, while adhering to PKZIPs format specification,
    * don't appear to be readable by some versions of WinZip and similar utilities. This is
    * probably because they use
    * a format specified for writing to a non-seakable stream, where the length and CRC of
    * a file is writen to a special block following the data. Since the length of the binary
    * date is unknown this makes an archive quite complicated to read, and it looks like
    * WinZip hasn't bothered.</p>
    * <p>All data is Deflated. Close completes the archive, flush terminates the current entry.</p>
    * @see java.util.zip.ZipOutputStream
    * @author  Malcolm McMahon
    public class ZipOutputFile extends java.io.OutputStream {
        byte[] oneByte = new byte[1];
        java.io.RandomAccessFile archive;
        public final static short DEFLATE_METHOD = 8;
        public final static short VERSION_CODE = 20;
        public final static short MIN_VERSION = 10;
        public final static int  ENTRY_HEADER_MAGIC = 0x04034b50;
        public final static int  CATALOG_HEADER_MAGIC = 0x02014b50;
        public final static int  CATALOG_END_MAGIC = 0x06054b50;
        private final static short DISC_NUMBER = 0;
        ByteBuffer entryHeader = ByteBuffer.wrap(new byte[30]);
        ByteBuffer entryLater = ByteBuffer.wrap(new byte[12]);
        java.util.zip.CRC32 crcAcc = new java.util.zip.CRC32();
        java.util.zip.Deflater def = new java.util.zip.Deflater(java.util.zip.Deflater.DEFLATED, true);
        int totalCompressed;
        long MSEPOCH;
        byte [] deflateBuf = new byte[2048];
        public static final long SECONDS_TO_DAYS = 60 * 60 * 24;
         * Entry stores info about each file stored
        private class Entry {
            long offset;        // position of header in file
            byte[] name;
            long crc;
            int compressedSize;
            int uncompressedSize;
            java.util.Date date;
             * Contructor also writes initial header.
             * @param fileName Name under which data is stored.
             * @param date  Date to label the file with
             * @TODO get the date stored properly
            public Entry(String fileName, java.util.Date date) throws IOException {
                name = fileName.getBytes();
                this.date = date == null ? new java.util.Date() : date;
                entryHeader.position(10);
                putDate(entryHeader);
                entryHeader.putShort(26, (short)name.length);
                offset = archive.getFilePointer();
                archive.write(entryHeader.array());
                archive.write(name);
                catalog.add(this);
                crcAcc.reset();
                totalCompressed = 0;
                def.reset();
             * Finish writing entry data. Save the lenghts & crc for catalog
             * and go back and fill them in in the entry header.
            public void close() throws IOException {
                def.finish();
                while(!def.finished())
                    deflate();
                entryLater.position(0);
                crc = crcAcc.getValue();
                compressedSize = totalCompressed;
                uncompressedSize = def.getTotalIn();
                entryLater.putInt((int)crc);
                entryLater.putInt(compressedSize);
                entryLater.putInt(uncompressedSize);
                long eof = archive.getFilePointer();
                archive.seek(offset + 14);
                archive.write(entryLater.array());
                archive.seek(eof);
             * Write the catalog data relevant to this entry. Buffer is
             * preloaded with fixed data.
             * @param buf Buffer to organise fixed lenght part of header
            public void writeCatalog(ByteBuffer buf) throws IOException {
                buf.position(12);
                putDate(buf);
                buf.putInt((int)crc);
                buf.putInt(compressedSize);
                buf.putInt(uncompressedSize);
                buf.putShort((short)name.length);
                buf.putShort((short)0);  // extra field length
                buf.putShort((short)0);  // file comment length
                buf.putShort(DISC_NUMBER);  // disk number
                buf.putShort((short)0); // internal attributes
                buf.putInt(0);      // external file attributes
                buf.putInt((int)offset); // file position
                archive.write(buf.array());
                archive.write(name);
             * This writes the entries date in MSDOS format.
             * @param buf Where to write it
             * @TODO Get this generating sane dates
            public void putDate(ByteBuffer buf) {
                long msTime = (date.getTime() - MSEPOCH) / 1000;
                buf.putShort((short)(msTime % SECONDS_TO_DAYS));
                buf.putShort((short)(msTime / SECONDS_TO_DAYS));
        private Entry entryInProgress = null; // entry currently being written
        private java.util.ArrayList catalog = new java.util.ArrayList(12);  // all entries
         * Start a new output file.
         * @param name The name to store as
         * @param date Date - null indicates current time
        public java.io.OutputStream openEntry(String name, java.util.Date date) throws IOException{
            if(entryInProgress != null)
                entryInProgress.close();
            entryInProgress = new Entry(name, date);
            return this;
         * Creates a new instance of ZipOutputFile
         * @param fd The file to write to
        public ZipOutputFile(java.io.File fd) throws IOException {
            this(new java.io.RandomAccessFile(fd, "rw"));
         * Create new instance of ZipOutputFile from RandomAccessFile
         * @param archive RandomAccessFile
        public ZipOutputFile(java.io.RandomAccessFile archive) {
            this.archive = archive;
            entryHeader.order(java.nio.ByteOrder.LITTLE_ENDIAN);  // create fixed fields of header
            entryLater.order(java.nio.ByteOrder.LITTLE_ENDIAN);
            entryHeader.putInt(ENTRY_HEADER_MAGIC);
            entryHeader.putShort(MIN_VERSION);
            entryHeader.putShort((short)0);  // general purpose flag
            entryHeader.putShort(DEFLATE_METHOD);
            java.util.Calendar cal = java.util.Calendar.getInstance();
            cal.clear();
            cal.set(java.util.Calendar.YEAR, 1950);
            cal.set(java.util.Calendar.DAY_OF_MONTH, 1);
    //        def.setStrategy(Deflater.HUFFMAN_ONLY);
            MSEPOCH = cal.getTimeInMillis();
         * Writes the master catalogue and postamble and closes the archive file.
        public void close() throws IOException{
            if(entryInProgress != null)
                entryInProgress.close();
            ByteBuffer catEntry = ByteBuffer.wrap(new byte[46]);
            catEntry.order(java.nio.ByteOrder.LITTLE_ENDIAN);
            catEntry.putInt(CATALOG_HEADER_MAGIC);
            catEntry.putShort(VERSION_CODE);
            catEntry.putShort(MIN_VERSION);
            catEntry.putShort((short)0);
            catEntry.putShort(DEFLATE_METHOD);
            long catStart = archive.getFilePointer();
            for(java.util.Iterator it = catalog.iterator(); it.hasNext();) {
                ((Entry)it.next()).writeCatalog(catEntry);
            catEntry.position(0);
            catEntry.putInt(CATALOG_END_MAGIC);
            catEntry.putShort(DISC_NUMBER);
            catEntry.putShort(DISC_NUMBER);
            catEntry.putShort((short)catalog.size());
            catEntry.putShort((short)catalog.size());
            catEntry.putInt((int)(archive.getFilePointer() - catStart));
            catEntry.putInt((int)catStart);
            catEntry.putShort((short)0);
            archive.write(catEntry.array(), 0, catEntry.position());
            archive.setLength(archive.getFilePointer());  // truncate if old file
            archive.close();
            def.end();
         * Closes entry in progress.
        public void flush() throws IOException{
            if(entryInProgress == null)
                throw new IllegalStateException("Must call openEntry before writing");
            entryInProgress.close();
            entryInProgress = null;
         * Standard write routine. Defined by {@link java.io.OutputStream}.
         * Can only be used once openEntry has defined the file.
         * @param b  Bytes to write
        public void write(byte[] b) throws IOException{
            if(entryInProgress == null)
                throw new IllegalStateException("Must call openEntry before writing");
            crcAcc.update(b);
            def.setInput(b);
            while(!def.needsInput())
                deflate();
         * Standard write routine. Defined by {@link java.io.OutputStream}.
         * Can only be used once openEntry has defined the file.
         * @param b  Bytes to write
        public void write(int b) throws IOException{
            oneByte[0] = (byte)b;
            crcAcc.update(b);
            write(oneByte, 0, 1);
         *  Standard write routine. Defined by {@link java.io.OutputStream}.
         * Can only be used once openEntry has defined the file.
         * @param b  Bytes to write
         * @param off Start offset
         * @param len Byte count
        public void write(byte[] b, int off, int len) throws IOException{
            if(entryInProgress == null)
                throw new IllegalStateException("Must call openEntry before writing");
            crcAcc.update(b, off, len);
            def.setInput(b, off, len);
            while(!def.needsInput())
                deflate();
        * Gets a buffer full of coded data from the deflater and writes it to archive.
        private void deflate() throws IOException {
            int len = def.deflate(deflateBuf);
            totalCompressed += len;
            if(len > 0)
                archive.write(deflateBuf, 0, len);

  • 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.

  • Java.util.zip: how to save file type

    HI,
    I have a written a program that zips PDF files and sends them as an attachment via email. This have been running daily for the last 1.5 years with no problems. Recently, some email providers have been striping the attachments or refusing the email, because I have used two file suffix on the attachment, e.g report.pdf.zip. I did this so that when the file is unzipped the .pdf extension remains and file is recognised, otherwise the document is treated as plain text or unknown format. How can I include the filetype in the zipped file, so that I can have report.pdf become report.zip, then when the user unzips the file has report.zip become report.pdf. I know the filetype is stored in the zip header, but I don't know how to do this using java.util.zip. Any help would be appreciated.
    Mike

    You see, zip files are inherently dumb. They don't "actually" have a file system in the strictest sense. The zip file format merely associates a String ID with some bytes. It's all on the client side where the magic happens. if I have three zip entries in a file, these are the entry names.
    1.) somedir/myfile.txt
    2.) someotherdir/myfile.txt
    3.) README
    when a client "unzipper" see these names, it realizes that "/" is a directory separator, so it makes the appropriate directories and places the bytes into files of that given name.
    So all you should have to do is make the zip entry with a name that ends in .pdf The client should do the rest.

  • IOException java.util.zip.ZipException: error in opening zip file

    Hi Folks,
    In my application one Zip file will be placed in the server. to unzip that zip file i have used java.util.Zip.
    It is working fine.but some times it gets the following error.
    **IOException java.util.zip.ZipException: error in opening zip file**
    why is it so? but very rarely. I couldnt identify the exact scenario, where it causes the problem.
    Normally that zip file contains set of images of customer.
    Please share your inputs.
    Thanks,
    Balu.

    Thanks for ur reply.
    EJB is not used in my application.
    VC++ application at customer side prepares the zip file, and it will upload that zip to te server using ftp.
    After uploading done, at the server end one java program(contains main function) will access that folder to unzip.
    Thanks,
    Balu.

  • 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.

  • Bug on native code of OJVM java.util.zip.CRC32.updateBytes(CRC32.java)

    I want to unzip OpenOffice 1.0 files inside the OJVM but it fails into the native method java.util.zip.CRC32.updateBytes(CRC32.java).
    The first execution of the code runs OK, but the second not.
    After a long wait it shutdown the connection and the oracle trace file shows an stack trace like this:
    *** 2003-04-18 11:31:31.926
    *** SESSION ID:(17.97) 2003-04-18 11:31:31.926
    java.lang.IllegalArgumentException
    at java.util.zip.CRC32.updateBytes(CRC32.java)
    at java.util.zip.CRC32.update(CRC32.java)
    at java.util.zip.ZipInputStream.read(ZipInputStream.java)
    at oracle.xml.parser.v2.XMLByteReader.fillByteBuffer(XMLByteReader.java:354)
    at oracle.xml.parser.v2.XMLUTF8Reader.fillBuffer(XMLUTF8Reader.java:142)
    at oracle.xml.parser.v2.XMLByteReader.saveBuffer(XMLByteReader.java:448)
    at oracle.xml.parser.v2.XMLReader.fillBuffer(XMLReader.java:2012)
    at oracle.xml.parser.v2.XMLReader.skipWhiteSpace(XMLReader.java:1800)
    at oracle.xml.parser.v2.NonValidatingParser.parseMisc(NonValidatingParser.java:305)
    at oracle.xml.parser.v2.NonValidatingParser.parseProlog(NonValidatingParser.java:274)
    at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:254)
    at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:225)
    at com.prism.cms.frontend.EditPropertiesActions.processUpload(EditPropertiesActions.java:1901)
    Exception signal: 11 (SIGSEGV), code: 1 (Address not mapped to object), addr: 0x6d3a74a0, PC: [0x40263600, eomake_reference_to_eobjec
    t()+80]
    Registers:
    %eax: 0x54a54000 %ebx: 0x40429c20 %ecx: 0x54a546bf
    %edx: 0x6d3a7478 %edi: 0x402b27d0 %esi: 0x45c718ac
    %esp: 0xbfffbf20 %ebp: 0xbfffbf48 %eip: 0x40263600
    %efl: 0x00010206
    The code of the java method is:
    public static void processUpload(String id_page, String longname,
    String filename, String filetype,
    String s00)
    throws SQLException {
    Integer p_id = new Integer(id_page);
    String toSource;
    XMLDocument doc = null;
    DOMParser theParser = null;
    InputStream XSLStream = null;
    BufferedWriter out = null;
    #sql { select path||name||'.html' into :toSource from pages where id_page=:p_id };
    if ("Cancel".equalsIgnoreCase(s00)) {
    Jxtp.redirecUrl("/dbprism/ldoc/live/edit.html?p_source="+toSource);
    return;
    if ("no-file".equals(filename) && "no-contenttpye".equals(filetype)) {
    Jxtp.redirecUrl("/dbprism/ldoc/live/edit.html?p_source="+toSource);
    return;
    if ("xml".equalsIgnoreCase(filetype))
    #sql { call CMSj.moveFromUpload(:filename,:p_id) };
    else if ("sxw".equalsIgnoreCase(filetype)) {
    XSLProcessor processor = new XSLProcessor();
    XSLStylesheet theXSLStylesheet = null;
    BLOB locator = null;
    // open sxw file, it will be in zip format with a file named content.xml
    // then convert content.xml to document-v10.dtd with an stylesheet
    #sql { select blob_content into :locator from wpg_document where name = :filename for update };
    ZipInputStream zin = new ZipInputStream(locator.binaryStreamValue());
    ZipEntry entry;
    try {
    while((entry=zin.getNextEntry())!=null)
    if ("content.xml".equalsIgnoreCase(entry.getName())) {
    Integer newVersion;
    CLOB dstDoc;
    CMSDocURLStreamHandlerFactory.enableCMSDocURLs();
    try {
    URL inUrl = new URL("cms:/stylesheets/sxw2document-v10.xsl");
    XSLStream = inUrl.openStream();
    // Create the Stylesheet from the stream
    theXSLStylesheet = processor.newXSLStylesheet(XSLStream);
    // Stores the document processing it with the given stylesheet
    theParser = new DOMParser();
    theParser.setValidationMode(theParser.NONVALIDATING);
    theParser.setBaseURL(new URL("cms:/dtd/"));
    theParser.parse(zin);
    doc = theParser.getDocument();
    #sql { SELECT NVL(MAX(version),0)+1 INTO :newVersion FROM content
    WHERE cn_id_page = :p_id };
    #sql { INSERT INTO content( cn_id_page, version, owner, status, source_file,
    file_size, content, created, modified, created_by,
    modified_by)
    VALUES ( :p_id, :newVersion, sys_context('cms_context','user_id'),
    'Uploaded', :filename, 0 , EMPTY_CLOB(), SYSDATE, SYSDATE,
    sys_context('cms_context','user_id'),
    sys_context('cms_context','user_id')) };
    #sql { SELECT content INTO :dstDoc FROM content
    WHERE cn_id_page = :p_id AND version = :newVersion for update };
    #sql { call DBMS_LOB.trim(:inout dstDoc,0) };
    out = new BufferedWriter(dstDoc.getCharacterOutputStream(),dstDoc.getChunkSize());
    processor.processXSL(theXSLStylesheet, doc, new PrintWriter(out));
    #sql { delete from wpg_document where name=:filename };
    } catch (SAXParseException spe) {
    throw new SQLException("processUpload SAXParseException: "+xmlError(spe));
    } catch (SAXException se) {
    throw new SQLException("processUpload SAXException: "+se.getLocalizedMessage());
    } catch (XSLException xsle) {
    throw new SQLException("processUpload XSLException: "+xsle.getLocalizedMessage());
    } finally {
    if (XSLStream!=null)
    XSLStream.close();
    if (theParser!=null)
    theParser = null;
    if (out!=null) {
    out.flush();
    out.close();
    zin.close();
    } catch (IOException ioe) {
    throw new SQLException("processUpload IOException: "+ioe.getLocalizedMessage());
    } finally {
    if (XSLStream!=null)
    XSLStream = null;
    if (out!=null)
    out = null;
    if (zin!=null)
    zin = null;
    Jxtp.redirecUrl("/dbprism/ldoc/live/edit.html?p_source="+toSource);
    Basically it takes the content from a BLOB column of the wpg_document table, unzip it using java.util.zip package, look for the file content.xml and parse it using Oracle XML toolkit.
    Using an open source utility which replace java.util.package (http://jazzlib.sourceforge.net/) it works perfect because is a pure java application.
    Best regards, Marcelo.
    PD: I am using Oracle 9.2.0.2 on Linux.

    The cause of errors was a dying Westen Digital drive, specially the 48G partition reserved only for $ORACLE_BASE (/dev/sdb3 mounted on /opt/oracle).
    A simple quick scan of unmounted partition (badblocks -v /dev/sdb3) reported more than thousand new bad blocks (compared to the last scan six months ago). Although I strongly believe, specially in the case of WDC drives, that the best utility to "repair" bad blocks is the one that opens a window and prints the message: "Go to the nearest shop and buy a new drive", I was very curious to prove my suspicion just on this drive. After zero-filling the partition with dd, then formatting it (mke2fs -cc) and mounting again, the 11g installation and database creation (on the same partition) successfully completed, performing fast and smoothly. To make sure it was not a casual event, I repeated the installation once again with full success. The database itself is working fine (by now). Well, the whole procedure took me more than four hours, but I'm pretty satisfied. I learned once again - stay away from Western Digital. As Oracle cannot rely on dying drive, my friend is going tomorrow to spend a 150+ euro on two 250G Seagate Barracudas and replace both WDC drives, even though the first drive seems to be healthy.
    In general there is no difference between loading correct data from good disk into bad memory and loading the incorrect data from dying disk into good memory. In both cases the pattern is damaged. For everyone who runs into the problem similar to this, and the cause cannot be easily determined, the rule of thumb must be:
    1. test memory and, if it shows any error, check sockets and test memory modules individually
    2. check disks for bad blocks regardless of the result of memory testing
    Therefore I consider your answer being generally correct.
    Regards
    NJ

  • Java.util.zip.ZipException Error

    I created a jar file, and put in C:\tools
    C:\tools>java -jar myjar.jar is working fine
    However, if I try to run myjar.jar in other directories, then I have problems.
    I already set the classpath:
    SET CLASSPATH=.;%CLASSPATH%;C:\tools\myjar.jar;
    Here's the error. Any ideas???
    C:\>java -jar myjar.jar
    Exception in thread "main" java.util.zip.ZipException: The system cannot find th
    e file specified
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:112)
    at java.util.jar.JarFile.<init>(JarFile.java:117)
    at java.util.jar.JarFile.<init>(JarFile.java:55)

    You always need to specify a proper file name when you use the -jar switch. If you are not in c:\tools you have to run with "java -jar c:\tools\myjar.jar".
    Setting the classpath in particular doesn't help becuase the file name given to the -jar switch will override all settings for classpath. http://java.sun.com/j2se/1.4/docs/tooldocs/findingclasses.html#userclass
    But since you now have myjar.jar in your classpath, you can run the application from any directory with "java your.main.ClassName" :)

  • Running JAR gives me java.util.zip.ZipException

    I just made a JAR--we'll call it MyApp.jar--containing some classes in the JAR's main directory (that is, not in any subfolder, just in the top level), and the following manifest that I put in from a text file i called "MANIFEST.MF":
    "Main-Class: MyApp (i also tried using "MyApp.class")
    Class-Path: smartjcommon_1.6.jar smartjprint_1.5.6.jar smartjprint_demo.jar
    Those JARs in the class-path are three JAR files in the same directory as MyApp.jar that are used as external libraries for my program. I go to the command prompt, go to the directory with these JARs, and type in:
    java -jar MyApp (i also tried adding -window at the end, as I've seen done, since it's a Swing program)
    and I get:
    Exception in thread "main" java.util.zip.ZipException: The system cannot find the file specified
    at java.util.zip.ZipFile.open(Native Method)
    etc etc
    I'm sure it's a very simple problem, but what am I doing wrong?

    You aren't spelling the name of the jar file correctly. Tryjava -jar MyApp.jarinstead.

Maybe you are looking for