Extracting Zip/Jar Files Different?

Discussion in 'Java' started by Mark F, Jul 21, 2004.

  1. Mark F

    Mark F Guest

    I'm trying to use this method for extracting Jar files. I already know it
    works for Zip files just fine but it seems to bomb with Jar files. No
    Exceptions are thrown it just exits with the following message:

    Extracting Zip File: CreateRelations.jar
    Extracting to: D:\CreateRelations
    Extracting: D:\CreateRelations\META-INF\MANIFEST.MF
    D:\CreateRelations\META-INF\MANIFEST.MF (The system cannot find the path
    specified)


    /**
    * Extracts the compressed file to the directory given as location.
    *
    * @param location The location where the file should be extracted. The
    * location does not need to already exist, it will be created if
    necessary.
    * @return boolean return value.
    */
    public boolean extract(File location) {

    InputStream in = null;
    boolean extracted = false;
    String entryName = "";
    File entryPath = null;
    try {
    in = new BufferedInputStream(new FileInputStream(_file));
    ZipInputStream zin = new ZipInputStream(in);
    ZipEntry e;
    while ( (e = zin.getNextEntry()) != null) {
    entryPath = new File(location.toString() + File.separator +
    e.getName());
    if (e.isDirectory()) {
    if (!FileOperation.directoryExists(entryPath)) {
    System.out.println("Creating: " + entryPath);
    FileOperation.mkdir(entryPath);
    }
    continue;
    }

    System.out.println("Extracting: " + entryPath.toString());
    FileOutputStream out = new FileOutputStream(entryPath);
    byte[] b = new byte[512];
    int len = 0;
    while ( (len = zin.read(b)) != -1) {
    out.write(b, 0, len);
    }
    out.close();

    }
    extracted = true;
    }
    catch (FileNotFoundException ex) {
    System.out.println(ex.getMessage());
    }
    catch (IOException io) {
    System.out.println(io.getMessage());
    }

    return extracted;

    }




    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
     
    Mark F, Jul 21, 2004
    #1
    1. Advertising

  2. Mark F

    Liz Guest

    "Mark F" <> wrote in message
    news:40feb7b1$...
    > I'm trying to use this method for extracting Jar files. I already know it
    > works for Zip files just fine but it seems to bomb with Jar files. No
    > Exceptions are thrown it just exits with the following message:
    >
    > Extracting Zip File: CreateRelations.jar
    > Extracting to: D:\CreateRelations
    > Extracting: D:\CreateRelations\META-INF\MANIFEST.MF
    > D:\CreateRelations\META-INF\MANIFEST.MF (The system cannot find the path
    > specified)


    It appears that it requires a manifest file to exist in the jar file, so
    just put one and try again.

    >
    >
    > /**
    > * Extracts the compressed file to the directory given as location.
    > *
    > * @param location The location where the file should be extracted. The
    > * location does not need to already exist, it will be created if
    > necessary.
    > * @return boolean return value.
    > */
    > public boolean extract(File location) {
    >
    > InputStream in = null;
    > boolean extracted = false;
    > String entryName = "";
    > File entryPath = null;
    > try {
    > in = new BufferedInputStream(new FileInputStream(_file));
    > ZipInputStream zin = new ZipInputStream(in);
    > ZipEntry e;
    > while ( (e = zin.getNextEntry()) != null) {
    > entryPath = new File(location.toString() + File.separator +
    > e.getName());
    > if (e.isDirectory()) {
    > if (!FileOperation.directoryExists(entryPath)) {
    > System.out.println("Creating: " + entryPath);
    > FileOperation.mkdir(entryPath);
    > }
    > continue;
    > }
    >
    > System.out.println("Extracting: " + entryPath.toString());
    > FileOutputStream out = new FileOutputStream(entryPath);
    > byte[] b = new byte[512];
    > int len = 0;
    > while ( (len = zin.read(b)) != -1) {
    > out.write(b, 0, len);
    > }
    > out.close();
    >
    > }
    > extracted = true;
    > }
    > catch (FileNotFoundException ex) {
    > System.out.println(ex.getMessage());
    > }
    > catch (IOException io) {
    > System.out.println(io.getMessage());
    > }
    >
    > return extracted;
    >
    > }
    >
    >
    >
    >
    > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
     
    Liz, Jul 21, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric McIntyre

    Jar files in Jar files

    Eric McIntyre, May 24, 2004, in forum: Java
    Replies:
    1
    Views:
    495
    Roedy Green
    May 24, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    613
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,767
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,846
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    689
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page