1 Reply Latest reply on Apr 18, 2003 9:47 AM by 843802

    problems on zipping and unzipping class files

      I am trying to add a class file to a new jar file using FileInputStream and JarOutputStream.

      I am getting a very unique problems.

      when I read a class file using FileInputStream from my local hard disk I am getting 30 bytes less than then actual file size (the difference in bytes is exactly 30 bytes for any file, either class or xml or java, I dont understand this concept). after reading the contents I am writing the bytes read to a jar file using JarOutputStream. This all gets done fine. But when I extract the class file written into the jar file and try to run the class it is giving me the exception as follows:

      java.lang.ClassNotFoundException: com.wipro.flowbrix.plugins.factory.NewClass
      Exception in thread "main" java.lang.ClassFormatError: com/wipro/flowbrix/plugins/factory/NewClass (Bad magic number)
      at java.lang.ClassLoader.defineClass0(Native Method)
      at java.lang.ClassLoader.defineClass(Unknown Source)
      at java.security.SecureClassLoader.defineClass(Unknown Source)
      at java.net.URLClassLoader.defineClass(Unknown Source)
      at java.net.URLClassLoader.access$100(Unknown Source)
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClassInternal(Unknown Source)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Unknown Source)

      The classpath to the folder from where I am running the file is set. I have double checked the classpath.

      any information or solutions regarding this would be of great help.
        • 1. Re: problems on zipping and unzipping class files
          A "magic number" is a short sequence of data at the beginning of a file used to identify the file. ".class" files, for instance, always start with OxCA, 0xFE, 0xBA and 0xBE.

          If the 30 bytes missing are at the beginning of your file, there's nothing suprising in getting a "ClassFormatError" exception.

          I think we should concentrate on your first problem. Can you post the code used to add the class file, please?